[cfe-commits] r71939 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Analysis/stack-addr-ps.c test/Sema/array-init.c test/Sema/compound-literal.c

Eli Friedman eli.friedman at gmail.com
Sat May 16 04:45:57 PDT 2009


Author: efriedma
Date: Sat May 16 06:45:48 2009
New Revision: 71939

URL: http://llvm.org/viewvc/llvm-project?rev=71939&view=rev
Log:
PR3009: Get rid of bogus warning for scalar compound literals.

This patch isn't quite ideal in that it eliminates the warning for 
constructs like "int a = {1};", where the braces are in fact redundant.  
However, that would have required a bunch of refactoring, and it's 
much less likely to cause confusion compared to redundant nested braces.


Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Analysis/stack-addr-ps.c
    cfe/trunk/test/Sema/array-init.c
    cfe/trunk/test/Sema/compound-literal.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat May 16 06:45:48 2009
@@ -538,7 +538,7 @@
     }
   }
 
-  if (T->isScalarType())
+  if (T->isScalarType() && !TopLevelObject)
     SemaRef.Diag(IList->getLocStart(), diag::warn_braces_around_scalar_init)
       << IList->getSourceRange()
       << CodeModificationHint::CreateRemoval(SourceRange(IList->getLocStart()))

Modified: cfe/trunk/test/Analysis/stack-addr-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/stack-addr-ps.c?rev=71939&r1=71938&r2=71939&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/stack-addr-ps.c (original)
+++ cfe/trunk/test/Analysis/stack-addr-ps.c Sat May 16 06:45:48 2009
@@ -24,7 +24,7 @@
 
 void* compound_literal(int x, int y) {
   if (x)
-    return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} expected-warning{{braces around scalar initializer}}
+    return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };

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

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Sat May 16 06:45:48 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-warning{{excess elements in scalar initializer}}
+  int x4 = { 1, 2 }; // expected-warning{{excess elements in scalar initializer}}
 
   int y[4][3] = { 
     { 1, 3, 5 },

Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=71939&r1=71938&r2=71939&view=diff

==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Sat May 16 06:45:48 2009
@@ -6,7 +6,7 @@
 static struct foo t2 = {0,0}; 
 static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}}
 static int *p = (int []){2,4}; 
-static int x = (int){1}; // -expected-warning{{braces around scalar initializer}}
+static int x = (int){1};
 
 static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
 static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'long'}}





More information about the cfe-commits mailing list