8

This compiles and runs 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;
    d.f<int>();
}

There's two problems with this code:

  1. f() is private, so d.f<int>() should fail to compile.
  2. f() is ambiguous, as it could be B::f() or C::f().

However, there's no diagnostic with /Wall and B::f() is called. Reversing the order D inherits from gets C::f() called, so I guess it's just using the first base class in the list.

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

isanae
  • 3,253
  • 1
  • 22
  • 47

1 Answers1

2

This is a bug with Visual C++. I can reproduce it with 2015 and 2012, but not on 2005. I've opened a bug report on Connect. The only workaround I have is to rename the function to have some unusual name so it can't be called accidentally.

isanae
  • 3,253
  • 1
  • 22
  • 47
  • I can also reproduce this on 2017 RC, but intellisense does flag it with a squiggle because it uses EDG. Gotta love it when intellisense is more compliant than the actual compiler. – isanae Mar 06 '17 at 22:55