From 39990b1e95721caf4dbe0cee68a46552f7f03dd1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 20 Jun 2018 21:58:20 +0000 Subject: Related to PR37768: improve diagnostics for class name shadowing. Diagnose the name of the class being shadowed by using declarations, and improve the diagnostics for the case where the name of the class is shadowed by a non-static data member in a class with constructors. In the latter case, we now always give the "member with the same name as its class" diagnostic regardless of the relative order of the member and the constructor, rather than giving an inscrutible diagnostic if the constructor appears second. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335182 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CXX/class/class.mem/p13.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ test/CXX/class/class.mem/p14.cpp | 5 ++--- test/CXX/drs/dr0xx.cpp | 5 ++--- 3 files changed, 51 insertions(+), 6 deletions(-) (limited to 'test/CXX') diff --git a/test/CXX/class/class.mem/p13.cpp b/test/CXX/class/class.mem/p13.cpp index bc01fd4d30..1b1c0c7f8f 100644 --- a/test/CXX/class/class.mem/p13.cpp +++ b/test/CXX/class/class.mem/p13.cpp @@ -67,3 +67,50 @@ struct X4 { // expected-note{{previous}} }; }; }; + +// This includes such things inherited from base classes. +struct B { + static int D0; + int Da() {}; + enum D1 {}; + struct D1a; + typedef int D2; + using D2a = int; + template struct D2b; + template void D2c(); + template static int D2d; + template using D2e = int; + union { int D4; }; + int Dtemplate; + int Dtemplate_with_ctors; +}; +struct B2 { int Dtemplate(); }; + +struct D0 : B { using B::D0; }; // expected-error {{member 'D0' has the same name as its class}} +struct Da : B { using B::Da; }; // expected-error {{member 'Da' has the same name as its class}} +struct D1 : B { using B::D1; }; // expected-error {{member 'D1' has the same name as its class}} +struct D1a : B { using B::D1a; }; // expected-error {{member 'D1a' has the same name as its class}} +struct D2 : B { using B::D2; }; // expected-error {{member 'D2' has the same name as its class}} +struct D2a : B { using B::D2a; }; // expected-error {{member 'D2a' has the same name as its class}} +struct D2b : B { using B::D2b; }; // expected-error {{member 'D2b' has the same name as its class}} +struct D2c : B { using B::D2c; }; // expected-error {{member 'D2c' has the same name as its class}} +struct D2d : B { using B::D2d; }; // expected-error {{member 'D2d' has the same name as its class}} +struct D2e : B { using B::D2e; }; // expected-error {{member 'D2e' has the same name as its class}} +struct D4 : B { using B::D4; }; // expected-error {{member 'D4' has the same name as its class}} + +template struct Dtemplate : B { + using B::Dtemplate; // expected-error {{member 'Dtemplate' has the same name as its class}} +}; +Dtemplate ok; +Dtemplate error; // expected-note {{in instantiation of}} + +template struct Dtemplate_with_ctors : B { + Dtemplate_with_ctors(); + using B::Dtemplate_with_ctors; // expected-error {{member 'Dtemplate_with_ctors' has the same name as its class}} +}; + +template struct CtorDtorName : B { + using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}} + CtorDtorName(); + ~CtorDtorName(); // expected-error {{expected the class name after '~' to name a destructor}} +}; diff --git a/test/CXX/class/class.mem/p14.cpp b/test/CXX/class/class.mem/p14.cpp index 3f14099ef8..a2f6061856 100644 --- a/test/CXX/class/class.mem/p14.cpp +++ b/test/CXX/class/class.mem/p14.cpp @@ -9,9 +9,8 @@ struct X0 { }; struct X1 { - int X1; // expected-note{{hidden by a non-type declaration of 'X1' here}} - X1(); // expected-error{{must use 'struct' tag to refer to type 'X1' in this scope}} \ - // expected-error{{expected member name or ';' after declaration specifiers}} + int X1; // expected-error{{member 'X1' has the same name as its class}} + X1(); }; struct X2 { diff --git a/test/CXX/drs/dr0xx.cpp b/test/CXX/drs/dr0xx.cpp index a311d8f339..048187814d 100644 --- a/test/CXX/drs/dr0xx.cpp +++ b/test/CXX/drs/dr0xx.cpp @@ -911,9 +911,8 @@ namespace dr80 { // dr80: yes static int B; // expected-error {{same name as its class}} }; struct C { - int C; // expected-note {{hidden by}} - // FIXME: These diagnostics aren't very good. - C(); // expected-error {{must use 'struct' tag to refer to}} expected-error {{expected member name}} + int C; // expected-error {{same name as its class}} + C(); }; struct D { D(); -- cgit v1.2.3