llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.82k stars 11.45k forks source link

Microsoft extensions allow to access private methods of template base class #29949

Open llvmbot opened 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 30601
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@rnk

Extended Description

The following code shouldn't compile (method f is private).

$ cat test.cpp
#include <stdio.h>

template<class T>
class Base {
  void f() { printf("private Base::f()\n"); }
};

template<class T>
struct Container : Base<T> {
  void g() { f(); }
};

int main() {
  Container<char> c;
  c.g();
  return 0;
}
$ clang test.cpp -o test.exe
test.cpp:10:14: warning: use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension [-Wmicrosoft-template]
  void g() { f(); }
             ^
             this->
test.cpp:15:5: note: in instantiation of member function 'Container<char>::g' requested here
  c.g();
    ^
test.cpp:5:8: note: must qualify identifier to find this declaration in dependent base class
  void f() { printf("private Base::f()\n"); }
       ^
1 warning generated.

$ test.exe
private Base::f()
rnk commented 5 years ago

Still an issue.