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:
f()
is private, so d.f<int>()
should fail to compile.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++?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With