diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-10-26 06:12:44 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-10-26 06:12:44 +0000 |
commit | 6bedcfa79f3adbb398fbc2c8813ba17a5d48f11d (patch) | |
tree | e9305a72c68fac642d4a55301401e3260ad38533 | |
parent | 3ae0bfa244b1733eadeef6ee707b516061c71157 (diff) | |
download | bcm5719-llvm-6bedcfa79f3adbb398fbc2c8813ba17a5d48f11d.tar.gz bcm5719-llvm-6bedcfa79f3adbb398fbc2c8813ba17a5d48f11d.zip |
Sema: Emit a nicer diagnostic when IndirectFieldDecls show up inappropriately in non-type template arguments
llvm-svn: 193462
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 4 | ||||
-rw-r--r-- | clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 198b479ba14..795774657c7 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/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<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; } diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp index c4db0027052..3f70ca7c81a 100644 --- a/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp +++ b/clang/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 <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}} } } |