r193462 - Sema: Emit a nicer diagnostic when IndirectFieldDecls show up inappropriately in non-type template arguments

David Majnemer david.majnemer at gmail.com
Fri Oct 25 23:12:44 PDT 2013


Author: majnemer
Date: Sat Oct 26 01:12:44 2013
New Revision: 193462

URL: http://llvm.org/viewvc/llvm-project?rev=193462&view=rev
Log:
Sema: Emit a nicer diagnostic when IndirectFieldDecls show up inappropriately in non-type template arguments

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=193462&r1=193461&r2=193462&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sat Oct 26 01:12:44 2013
@@ -4361,9 +4361,9 @@ CheckTemplateArgumentAddressOfObjectOrFu
   ValueDecl *Entity = DRE->getDecl();
 
   // Cannot refer to non-static data members
-  if (FieldDecl *Field = dyn_cast<FieldDecl>(Entity)) {
+  if (isa<FieldDecl>(Entity) || isa<IndirectFieldDecl>(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;
   }

Modified: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp?rev=193462&r1=193461&r2=193462&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp Sat Oct 26 01:12:44 2013
@@ -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 <int* p> struct X0 { }; // expected-note 4{{here}}
+  template <int* p> struct X0 { }; // expected-note 5{{here}}
   template <int (*fp)(int)> struct X1 { };
   template <int &p> struct X2 { }; // expected-note 4{{here}}
   template <const int &p> 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 <typename T> T f_tmpl(T t);
+  struct S { union { int NonStaticMember; }; };
 
   void test() {
     X0<i> 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}}
   }
 }
 





More information about the cfe-commits mailing list