[cfe-commits] r113723 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
Douglas Gregor
dgregor at apple.com
Sun Sep 12 00:37:24 PDT 2010
Author: dgregor
Date: Sun Sep 12 02:37:24 2010
New Revision: 113723
URL: http://llvm.org/viewvc/llvm-project?rev=113723&view=rev
Log:
Diagnose the instantiation of variables (including static data
members) with function type. Fixes PR8047.
Added:
cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp (with props)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=113723&r1=113722&r2=113723&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Sep 12 02:37:24 2010
@@ -1602,6 +1602,8 @@
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">;
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=113723&r1=113722&r2=113723&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sun Sep 12 02:37:24 2010
@@ -349,6 +349,12 @@
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(),
Added: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp?rev=113723&view=auto
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp Sun Sep 12 02:37:24 2010
@@ -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}}
+
Propchange: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list