]> granicus.if.org Git - clang/commitdiff
PR3009: Get rid of bogus warning for scalar compound literals.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 16 May 2009 11:45:48 +0000 (11:45 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 16 May 2009 11:45:48 +0000 (11:45 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71939 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a8a0ea3aeacd2419bea9c33d6fe80c869b76fc8b..17113f68bd466f265b82e18b9ae9c0c61befc08a 100644 (file)
@@ -538,7 +538,7 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T,
     }
   }
 
-  if (T->isScalarType())
+  if (T->isScalarType() && !TopLevelObject)
     SemaRef.Diag(IList->getLocStart(), diag::warn_braces_around_scalar_init)
       << IList->getSourceRange()
       << CodeModificationHint::CreateRemoval(SourceRange(IList->getLocStart()))
index aa3c135f374529a0d075accac165c1cfd83e8e98..4bc9a7def2c82e8f3dce49a0539dbe1637258a91 100644 (file)
@@ -24,7 +24,7 @@ int* f3(int x, int *y) {
 
 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; };
index 4e95a0187601c12119951713934ac331be68cee6..dfaaa87ef5bf0a9b1d9da9d8c0fd5acfe3bfb74b 100644 (file)
@@ -20,7 +20,7 @@ void func() {
 
   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 },
index 24ec223ae6a21c135ead533cf414df7c6ef845b4..b51bcfe2a233a5529f02f0e77ceb8b0b3a0b1793 100644 (file)
@@ -6,7 +6,7 @@ static struct foo t = (struct foo){0,0};
 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'}}