Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No access or ambiguity check on templated member function found in multiple base classes

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++?

like image 721
isanae Avatar asked Jun 11 '16 18:06

isanae


1 Answers

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.

like image 67
isanae Avatar answered Nov 14 '22 17:11

isanae