Last active
January 7, 2016 01:18
-
-
Save dislogical/0223ec6a163e33ce6b7b to your computer and use it in GitHub Desktop.
Constructor Inheritance: clang v. msvc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MSVC Version: 18.00.40629 | |
| // Command line: cl ctors.cpp | |
| // Clang Version: 3.7.0 | |
| // Command line: clang++ ctors.cpp -std=c++11 | |
| struct A | |
| { | |
| A() = delete; | |
| A(const A&) = delete; | |
| A(A&&) = delete; | |
| template <class... Ts> | |
| A(Ts... ts) { } | |
| }; | |
| struct B : public A | |
| { | |
| using A::A; | |
| }; | |
| int main() | |
| { | |
| A a1; // clang: disallowed msvc: disallowed (good) | |
| B b1; // clang: disallowed msvc: allowed (bad) | |
| A a2(1, 2, 3); // clang: allowed msvc: allowed (good) | |
| B b2(1, 2, 3); // clang: allowed msvc: disallowed (bad) | |
| return 0; | |
| } | |
| // Full compiler output: | |
| /* MSVC: | |
| test.cpp(18) : error C2280: 'A::A(void)' : attempting to reference a deleted function | |
| test.cpp(3) : see declaration of 'A::A' | |
| test.cpp(22) : error C2661: 'B::B' : no overloaded function takes 3 arguments | |
| * Clang: | |
| test.cpp:18:7: error: call to deleted constructor of 'A' | |
| A a1; // clang: disallowed msvc: disallowed (good) | |
| ^ | |
| test.cpp:3:5: note: 'A' has been explicitly marked deleted here | |
| A() = delete; | |
| ^ | |
| test.cpp:19:7: error: call to implicitly-deleted default constructor of 'B' | |
| B b1; // clang: disallowed msvc: allowed (bad) | |
| ^ | |
| test.cpp:11:12: note: default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default | |
| constructor | |
| struct B : public A | |
| ^ | |
| test.cpp:3:5: note: 'A' has been explicitly marked deleted here | |
| A() = delete; | |
| ^ | |
| 2 errors generated. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment