forked from OSchip/llvm-project
Diagnose the instantiation of variables (including static data
members) with function type. Fixes PR8047. llvm-svn: 113723
This commit is contained in:
parent
6309e3d18e
commit
6162334ce0
|
@ -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">;
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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}}
|
||||
|
Loading…
Reference in New Issue