[cfe-commits] r64964 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaInit.cpp test/Sema/array-init.c test/Sema/designated-initializers.c test/Sema/flexible-array-init.c test/Sema/init.c test/Sema/vector-init.c

Douglas Gregor dgregor at apple.com
Wed Feb 18 14:23:55 PST 2009


Author: dgregor
Date: Wed Feb 18 16:23:55 2009
New Revision: 64964

URL: http://llvm.org/viewvc/llvm-project?rev=64964&view=rev
Log:
Downgrade the "excess elements in initializer" errors to warnings *in
C*. They're required errors in C++.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/array-init.c
    cfe/trunk/test/Sema/designated-initializers.c
    cfe/trunk/test/Sema/flexible-array-init.c
    cfe/trunk/test/Sema/init.c
    cfe/trunk/test/Sema/vector-init.c

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Wed Feb 18 16:23:55 2009
@@ -685,8 +685,12 @@
      "initialization with '{...}' expected for array")
 DIAG(err_excess_initializers, ERROR,
      "excess elements in %select{array|vector|scalar|union|struct}0 initializer")
+DIAG(warn_excess_initializers, WARNING,
+     "excess elements in %select{array|vector|scalar|union|struct}0 initializer")
 DIAG(err_excess_initializers_in_char_array_initializer, ERROR,
     "excess elements in char array initializer")
+DIAG(warn_excess_initializers_in_char_array_initializer, WARNING,
+    "excess elements in char array initializer")
 DIAG(warn_initializer_string_for_char_array_too_long, WARNING,
     "initializer-string for char array is too long")
 DIAG(warn_braces_around_scalar_init, WARNING,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Feb 18 16:23:55 2009
@@ -323,9 +323,11 @@
     // We have leftover initializers
     if (IList->getNumInits() > 0 &&
         SemaRef->IsStringLiteralInit(IList->getInit(Index), T)) {
+      unsigned DK = diag::warn_excess_initializers_in_char_array_initializer;
+      if (SemaRef->getLangOptions().CPlusPlus)
+        DK = diag::err_excess_initializers_in_char_array_initializer;
       // Special-case
-      SemaRef->Diag(IList->getInit(Index)->getLocStart(),
-                    diag::err_excess_initializers_in_char_array_initializer)
+      SemaRef->Diag(IList->getInit(Index)->getLocStart(), DK)
         << IList->getInit(Index)->getSourceRange();
       hadError = true; 
     } else if (!T->isIncompleteType()) {
@@ -338,8 +340,12 @@
         CurrentObjectType->isScalarType()? 2 :
         CurrentObjectType->isUnionType()? 3 :
         4;
-      SemaRef->Diag(IList->getInit(Index)->getLocStart(), 
-                    diag::err_excess_initializers)
+
+      unsigned DK = diag::warn_excess_initializers;
+      if (SemaRef->getLangOptions().CPlusPlus)
+          DK = diag::err_excess_initializers;
+
+      SemaRef->Diag(IList->getInit(Index)->getLocStart(), DK)
         << initKind << IList->getInit(Index)->getSourceRange();
     }
   }

Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=64964&r1=64963&r2=64964&view=diff

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Wed Feb 18 16:23:55 2009
@@ -20,7 +20,7 @@
 
   int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
 
-  int x4 = { 1, 2 }; // expected-warning{{braces around scalar initializer}} expected-error{{excess elements in scalar initializer}}
+  int x4 = { 1, 2 }; // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in scalar initializer}}
 
   int y[4][3] = { 
     { 1, 3, 5 },
@@ -37,7 +37,7 @@
     { 2, 4, 6 },
     { 3, 5, 7 },
     { 4, 6, 8 },
-    { 5 }, // expected-error{{excess elements in array initializer}}
+    { 5 }, // expected-warning{{excess elements in array initializer}}
   };
 
   struct threeElements {
@@ -53,17 +53,17 @@
 
 void test() {
   int y1[3] = { 
-    { 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-error{{excess elements in scalar initializer}}
+    { 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in scalar initializer}}
   };
   int y3[4][3] = {  
     { 1, 3, 5 },
     { 2, 4, 6 },
     { 3, 5, 7 },
     { 4, 6, 8 },
-    {  }, // expected-warning{{use of GNU empty initializer extension}} expected-error{{excess elements in array initializer}}
+    {  }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}}
   };
   int y4[4][3] = {  
-    { 1, 3, 5, 2 }, // expected-error{{excess elements in array initializer}}
+    { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}}
     { 4, 6 },
     { 3, 5, 7 },
     { 4, 6, 8 },
@@ -149,7 +149,7 @@
 	static char const test[] = "test";
         int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
 	static char const test2[] = { "weird stuff" };
-	static char const test3[] = { "test", "excess stuff" }; // expected-error{{excess elements in char array initializer}}
+	static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
 
   char* cp[] = { "Hello" };
 
@@ -157,7 +157,7 @@
   int l[sizeof(c) == 6 ? 1 : -1];
   
   int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'char [7]', expected 'int'}}
-  char c2[] = { "Hello", "Good bye" }; //expected-error{{excess elements in char array initializer}}
+  char c2[] = { "Hello", "Good bye" }; //expected-warning{{excess elements in char array initializer}}
 
   int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'char [6]', expected 'int'}}
   char c3[5] = { "Hello" };
@@ -178,7 +178,7 @@
 char r3[][5] = {1,2,3,4,5,6};
 int r3_sizecheck[(sizeof(r3) / sizeof(char[5])) == 2? 1 : -1];
 char r3_2[sizeof r3 == 10 ? 1 : -1];
-float r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-error{{excess elements in array initializer}}
+float r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
 char r5[][5] = {"aa", "bbb", "ccccc"};
 char r6[sizeof r5 == 15 ? 1 : -1];
 const char r7[] = "zxcv";
@@ -207,7 +207,7 @@
 int t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1];
 
 struct bittest{int : 31, a, :21, :12, b;};
-struct bittest bittestvar = {1, 2, 3, 4}; //expected-error{{excess elements in struct initializer}}
+struct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in struct initializer}}
 
 // Not completely sure what should happen here...
 int u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}}
@@ -242,7 +242,7 @@
 };
 
 static void sppp_ipv6cp_up();
-const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct extension}} expected-error{{excess elements in struct initializer}}
+const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct extension}} expected-warning{{excess elements in struct initializer}}
 
 struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a GNU extension in C}}
 typedef struct _Matrix Matrix;

Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=64964&r1=64963&r2=64964&view=diff

==============================================================================
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Wed Feb 18 16:23:55 2009
@@ -185,4 +185,4 @@
                               .arr2[1] = 0xffff,
                               .arr2[2] = 0xffff };
 
-const union wibble wobble2 = { .arr2 = {4, 5, 6}, 7 }; // expected-error{{excess elements in union initializer}}
+const union wibble wobble2 = { .arr2 = {4, 5, 6}, 7 }; // expected-warning{{excess elements in union initializer}}

Modified: cfe/trunk/test/Sema/flexible-array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/flexible-array-init.c?rev=64964&r1=64963&r2=64964&view=diff

==============================================================================
--- cfe/trunk/test/Sema/flexible-array-init.c (original)
+++ cfe/trunk/test/Sema/flexible-array-init.c Wed Feb 18 16:23:55 2009
@@ -4,7 +4,7 @@
   int values[];
 } x = {5, {1, 2, 3}};
 
-struct one x2 = { 5, 1, 2, 3 }; // expected-error{{excess elements in struct initializer}}
+struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{excess elements in struct initializer}}
 
 void test() {
   struct one x3 = {5, {1, 2, 3}};

Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=64964&r1=64963&r2=64964&view=diff

==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Wed Feb 18 16:23:55 2009
@@ -108,3 +108,5 @@
 struct foo2 bar2[] = {
    { (intptr_t)bbb }
 };
+
+struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}

Modified: cfe/trunk/test/Sema/vector-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-init.c?rev=64964&r1=64963&r2=64964&view=diff

==============================================================================
--- cfe/trunk/test/Sema/vector-init.c (original)
+++ cfe/trunk/test/Sema/vector-init.c Wed Feb 18 16:23:55 2009
@@ -1,15 +1,17 @@
 // RUN: clang %s -fsyntax-only -verify
 
-typedef __attribute__(( ext_vector_type(4) ))  float float4;
-//typedef float float4 __attribute__((vector_size(16)));
+//typedef __attribute__(( ext_vector_type(4) ))  float float4;
+typedef float float4 __attribute__((vector_size(16)));
 
 float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
 
+float4 foo2 = (float4){ 1.0, 2.0, 3.0, 4.0 , 5.0 }; // expected-warning{{excess elements in vector initializer}}
+
 float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
 int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3? 1 : -1];
 
 float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 
-                     9.0 }; // expected-error {{excess elements in array initializer}}
+                     9.0 }; // expected-warning {{excess elements in array initializer}}
 
 float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0,
-                     9.0 }; // expected-error {{excess elements in array initializer}}
+                     9.0 }; // expected-warning {{excess elements in array initializer}}





More information about the cfe-commits mailing list