[cfe-commits] r69226 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.cpp test/Parser/recovery.c test/Sema/incomplete-decl.c

Daniel Dunbar daniel at zuster.org
Wed Apr 15 14:35:30 PDT 2009


Author: ddunbar
Date: Wed Apr 15 16:35:27 2009
New Revision: 69226

URL: http://llvm.org/viewvc/llvm-project?rev=69226&view=rev
Log:
Add warning when a tentative array definition is assumed to have one element.
 - Also, fixed one to actually be one (instead of zero). :)

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/Parser/recovery.c
    cfe/trunk/test/Sema/incomplete-decl.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69226&r1=69225&r2=69226&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 15 16:35:27 2009
@@ -944,6 +944,8 @@
   "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<

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=69226&r1=69225&r2=69226&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Apr 15 16:35:27 2009
@@ -253,8 +253,9 @@
               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);

Modified: cfe/trunk/test/Parser/recovery.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/recovery.c?rev=69226&r1=69225&r2=69226&view=diff

==============================================================================
--- cfe/trunk/test/Parser/recovery.c (original)
+++ cfe/trunk/test/Parser/recovery.c Wed Apr 15 16:35:27 2009
@@ -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}}
 };

Modified: cfe/trunk/test/Sema/incomplete-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/incomplete-decl.c?rev=69226&r1=69225&r2=69226&view=diff

==============================================================================
--- cfe/trunk/test/Sema/incomplete-decl.c (original)
+++ cfe/trunk/test/Sema/incomplete-decl.c Wed Apr 15 16:35:27 2009
@@ -11,7 +11,7 @@
 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 @@
   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'}} \





More information about the cfe-commits mailing list