Clang fails to compile the following code that succeeds with cl.exe class A {}; template <class T> class B { void (T::*mCallOnResume)(); }; namespace q { class C : A, B<C> { }; };
Here's a slightly saner reduction: class A {}; template <class T> class B { void (T::*mCallOnResume)(); }; class C : A, B<C> { }; C p;
As a workaround, you can do this: class A {}; template <class T> class B { void (T::*mCallOnResume)(); }; class __multiple_inheritance C; // workaround class C : A, B<C> { }; Our diagnostic is bad, but here's what's happening: - We parse C's base specifiers - Instantiate B<C> - RequireCompleteType on 'void (C::*)()' - RequireCompleteType on C, lock in the inheritance model, probably as single inheritance, because we haven't set C's base specifiers yet - Finish C's definition, realize that we assumed C was using single inheritance when it really used multiple inheritance.
Thanks a lot for the analysis and workaround, Reid! I'll try to work with Jeff tomorrow to see how we can apply this workaround to our code. I have to admit that I don't entirely understand the implications of these MSVC keywords (I just learned about their existence yesterday.) I assume the workaround won't change how the code will behave when built with cl?
marginally reduced: template <class T> class A { int T::*x; }; class B : virtual A<B> {};
Fixed in r210886.
I should point out that while we have fixed this in clang, note that sizeof(mCallOnResume) will probably be 16 (1 pointer and 3 ints!) on x86 with both MSVC and Clang. That's probably larger than you wanted. The __multiple_inheritance workaround that I gave should make it just 8 (1 pointer and 1 int).
It seems the fix is not 100% correct. We are using clang through libTooling, -v gives: clang version 3.6.0 (branches/release_36 230502) (llvm/branches/release_36 230501). code (simplified) : class A : public B<wchar_t> { public: // ... typedef bool (A::*C)(const D<wchar_t>&, E&, int, const F&); // ... static C m[]; // ... }; clang output: In file included from ... ... a.h:95:1: error: inheritance model does not match definition class A : public B<wchar_t> ^ a.h:95:7: note: A defined here class A : public B<wchar_t> ^ 1 error generated. Error while processing ....cpp.
József, I cannot reproduce with what you have posted. Please provide a complete example.