Teach Sema::ActOnCompoundLiteral about constraint C99 6.5.2.5p3.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45782 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 7d224c5..8974325 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -664,8 +664,9 @@
   Expr *literalExpr = static_cast<Expr*>(InitExpr);
 
   // FIXME: add more semantic analysis (C99 6.5.2.5).
-  if (CheckInitializer(literalExpr, literalType, false))
-    return 0;
+  bool requireConstantExprs = !CurFunctionDecl && !CurMethodDecl;
+  if (CheckInitializer(literalExpr, literalType, requireConstantExprs))
+    return true;
 
   return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr);
 }
diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c
index 2c9595c..12ee9f9 100644
--- a/test/Sema/compound-literal.c
+++ b/test/Sema/compound-literal.c
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify -pedantic %s
 
 struct foo { int a, b; };
 
@@ -8,9 +8,13 @@
 static int *p = (int []){2,4}; 
 static int x = (int){1}; // -expected-error {{initializer element is not constant}} -expected-warning{{braces around scalar initializer}}
 
+static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}}
+static int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char *', expected 'int'}}
+
 extern void fooFunc(struct foo *pfoo);
 
 int main(int argc, char **argv) {
+ int *l = (int []){x, *p, *p2};
  fooFunc(&(struct foo){ 1, 2 });
 }