diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-09-12 07:37:24 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-09-12 07:37:24 +0000 |
commit | c6dbc3fa467e2355b678a6b717534928048efcb2 (patch) | |
tree | 9af1e43cf0a21228ac677e7e38773c9dc039cf8d | |
parent | da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892 (diff) |
Diagnose the instantiation of variables (including static data
members) with function type. Fixes PR8047.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113723 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 6 | ||||
-rw-r--r-- | test/CXX/temp/temp.arg/temp.arg.type/p2.cpp | 12 |
3 files changed, 20 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9a2102b743..b79b24f335 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1602,6 +1602,8 @@ def note_instantiation_contexts_suppressed : Note< def err_field_instantiates_to_function : Error< "data member instantiated with function type %0">; +def err_variable_instantiates_to_function : Error< + "%select{variable|static data member}0 instantiated with function type %1">; def err_nested_name_spec_non_tag : Error< "type %0 cannot be used prior to '::' because it has no members">; diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index b8690f6eb2..c97a8788ef 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -349,6 +349,12 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { if (!DI) return 0; + if (DI->getType()->isFunctionType()) { + SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function) + << D->isStaticDataMember() << DI->getType(); + return 0; + } + // Build the instantiated declaration VarDecl *Var = VarDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), diff --git a/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp b/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp new file mode 100644 index 0000000000..0384aa70fa --- /dev/null +++ b/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template<class T> struct A { + static T t; // expected-error{{static data member instantiated with function type 'int ()'}} +}; +typedef int function(); +A<function> a; // expected-note{{instantiation of}} + +template<typename T> struct B { + B() { T t; } // expected-error{{variable instantiated with function type 'int ()'}} +}; +B<function> b; // expected-note{{instantiation of}} + |