From: David Majnemer Date: Sat, 26 Oct 2013 06:12:44 +0000 (+0000) Subject: Sema: Emit a nicer diagnostic when IndirectFieldDecls show up inappropriately in... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=099791143ba548bf0a228da0d268b463a3507929;p=clang Sema: Emit a nicer diagnostic when IndirectFieldDecls show up inappropriately in non-type template arguments git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193462 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 198b479ba1..795774657c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4361,9 +4361,9 @@ CheckTemplateArgumentAddressOfObjectOrFunction(Sema &S, ValueDecl *Entity = DRE->getDecl(); // Cannot refer to non-static data members - if (FieldDecl *Field = dyn_cast(Entity)) { + if (isa(Entity) || isa(Entity)) { S.Diag(Arg->getLocStart(), diag::err_template_arg_field) - << Field << Arg->getSourceRange(); + << Entity << Arg->getSourceRange(); S.Diag(Param->getLocation(), diag::note_template_param_here); return true; } diff --git a/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp b/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp index c4db002705..3f70ca7c81 100644 --- a/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp +++ b/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp @@ -27,7 +27,7 @@ namespace non_type_tmpl_param { // omitted if the name refers to a function or array and shall be omitted // if the corresopnding template-parameter is a reference; or namespace addr_of_obj_or_func { - template struct X0 { }; // expected-note 4{{here}} + template struct X0 { }; // expected-note 5{{here}} template struct X1 { }; template struct X2 { }; // expected-note 4{{here}} template struct X2k { }; // expected-note {{here}} @@ -40,6 +40,7 @@ namespace addr_of_obj_or_func { __thread int ti = 100; // expected-note 2{{here}} static int f_internal(int); // expected-note 4{{here}} template T f_tmpl(T t); + struct S { union { int NonStaticMember; }; }; void test() { X0 x0a; // expected-error {{must have its address taken}} @@ -78,6 +79,7 @@ namespace addr_of_obj_or_func { X0<&n> x0_no_linkage; // expected-error {{non-type template argument refers to object 'n' that does not have linkage}} struct Local { static int f() {} }; // expected-note {{here}} X1<&Local::f> x1_no_linkage; // expected-error {{non-type template argument refers to function 'f' that does not have linkage}} + X0<&S::NonStaticMember> x0_non_static; // expected-error {{non-static data member}} } }