[cfe-commits] r86165 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp test/SemaCXX/dependent-types.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Nov 5 11:47:47 PST 2009
Author: cornedbee
Date: Thu Nov 5 13:47:47 2009
New Revision: 86165
URL: http://llvm.org/viewvc/llvm-project?rev=86165&view=rev
Log:
Don't allow definitions of array variables without some size information in C++. Fixed PR5401
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp
cfe/trunk/test/SemaCXX/dependent-types.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=86165&r1=86164&r2=86165&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Nov 5 13:47:47 2009
@@ -1488,6 +1488,9 @@
"tentative definition has array of type %0 that is never completed">;
def warn_tentative_incomplete_array : Warning<
"tentative array definition assumed to have one element">;
+def err_typecheck_incomplete_array_needs_initializer : Error<
+ "definition of variable with array type needs an explicit size "
+ "or an initializer">;
def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">;
def err_typecheck_sclass_fscope : Error<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=86165&r1=86164&r2=86165&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Nov 5 13:47:47 2009
@@ -3433,6 +3433,16 @@
return;
}
+ // An array without size is an incomplete type, and there are no special
+ // rules in C++ to make such a definition acceptable.
+ if (getLangOptions().CPlusPlus && Type->isIncompleteArrayType() &&
+ !Var->hasExternalStorage()) {
+ Diag(Var->getLocation(),
+ diag::err_typecheck_incomplete_array_needs_initializer);
+ Var->setInvalidDecl();
+ return;
+ }
+
// C++ [temp.expl.spec]p15:
// An explicit specialization of a static data member of a template is a
// definition if the declaration includes an initializer; otherwise, it
Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp?rev=86165&r1=86164&r2=86165&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp Thu Nov 5 13:47:47 2009
@@ -20,7 +20,7 @@
int ar7[0u]; // expected-warning {{zero size arrays are an extension}}
// An array with unknown bound is incomplete.
-int ar8[]; // FIXME: This needs to fail!
+int ar8[]; // expected-error {{needs an explicit size or an initializer}}
// So is an array with an incomplete element type.
struct Incomplete; // expected-note {{forward declaration}}
Incomplete ar9[10]; // expected-error {{incomplete type}}
Modified: cfe/trunk/test/SemaCXX/dependent-types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dependent-types.cpp?rev=86165&r1=86164&r2=86165&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/dependent-types.cpp (original)
+++ cfe/trunk/test/SemaCXX/dependent-types.cpp Thu Nov 5 13:47:47 2009
@@ -4,7 +4,7 @@
T x1;
T* x2;
T& x3; // expected-error{{declaration of reference variable 'x3' requires an initializer}}
- T x4[]; // expected-error{{variable has incomplete type 'T []'}}
+ T x4[]; // expected-error{{needs an explicit size or an initializer}}
T x5[Size];
int x6[Size];
}
More information about the cfe-commits
mailing list