diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-04-15 21:35:27 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-04-15 21:35:27 +0000 |
commit | dbb4f21125699f207ce7accfc52fdd99f47ce352 (patch) | |
tree | 9ddc8e68febb70126741a51b1bef32051b3dc037 | |
parent | 68a2eb0cc76267ba0615992fb5e0977853c397b2 (diff) |
Add warning when a tentative array definition is assumed to have one element.
- Also, fixed one to actually be one (instead of zero). :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69226 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 5 | ||||
-rw-r--r-- | test/Parser/recovery.c | 2 | ||||
-rw-r--r-- | test/Sema/incomplete-decl.c | 4 |
4 files changed, 8 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a77045e437..a6586a8246 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -944,6 +944,8 @@ def err_tentative_def_incomplete_type : Error< "tentative definition has type %0 that is never completed">; def err_tentative_def_incomplete_type_arr : Error< "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_realimag_invalid_type : Error<"invalid type %0 to %1 operator">; def err_typecheck_sclass_fscope : Error< diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 403e8f60f5..ed5c431da8 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -253,8 +253,9 @@ void Sema::ActOnEndOfTranslationUnit() { VD->setInvalidDecl(); else { // Set the length of the array to 1 (C99 6.9.2p5). - llvm::APSInt One(Context.getTypeSize(Context.getSizeType()), - true); + Diag(VD->getLocation(), diag::warn_tentative_incomplete_array); + llvm::APInt One(Context.getTypeSize(Context.getSizeType()), + true); QualType T = Context.getConstantArrayType(ArrayT->getElementType(), One, ArrayType::Normal, 0); diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c index 1d49525f3b..3f2d48d0f7 100644 --- a/test/Parser/recovery.c +++ b/test/Parser/recovery.c @@ -1,7 +1,7 @@ // RUN: clang-cc -fsyntax-only -verify -pedantic -fblocks %s // PR2241 -float test2241[] = { +float test2241[2] = { 1e, // expected-error {{exponent}} 1ee0 // expected-error {{exponent}} }; diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index c4183ca72f..eb93e8e380 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -11,7 +11,7 @@ static struct foo g; // expected-error {{variable has incomplete type 'struct f extern void d; extern struct foo e; -int ary[]; +int ary[]; // expected-warning {{tentative array definition assumed to have one element}} struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}} void func() { @@ -20,7 +20,7 @@ void func() { struct foo f; // expected-error {{variable has incomplete type 'struct foo'}} } -int h[]; +int h[]; // expected-warning {{tentative array definition assumed to have one element}} int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}} struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \ |