No access or ambiguity checking on a template member function found in several base classes

This compiles and works fine on Visual C ++ 2015 Update 3 RC:

class A { template <class T> void f() {} }; class B : A {}; class C : A {}; class D : B, C {}; int main() { D d; df<int>(); } 

There are two problems in this code:

  • f() is private, so df<int>() should not compile.
  • f() is ambiguous, as it can be B::f() or C::f() .

However, the diagnosis with /Wall and B::f() not called. The reverse order of D inherited from get C::f() , so I assume that it just uses the first base class in the list.

Both g ++ and clang get this right. Am I missing something or is this a bug in Visual C ++?

+8
c ++ private multiple-inheritance visual-c ++ ambiguous
source share
1 answer

This is a bug with Visual C ++. I can reproduce it from 2015 to 2012, but not in 2005. I opened a bug report in Connect . The only workaround I have is to rename the function so that it has some unusual name so that it cannot be called accidentally.

+2
source share

All Articles