]> granicus.if.org Git - clang/commitdiff
Merge branch 'format-string-braced-init'
authorMatt Beaumont-Gay <matthewbg@google.com>
Fri, 11 May 2012 22:10:59 +0000 (22:10 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Fri, 11 May 2012 22:10:59 +0000 (22:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156653 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/format-strings.c

index bc4452f125d0c90980de7e2b2d78e67e96924996..eddb612fc6eab98cd89afdf0875e3e34ce6eb51c 100644 (file)
@@ -1569,10 +1569,16 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args,
       }
 
       if (isConstant) {
-        if (const Expr *Init = VD->getAnyInitializer())
+        if (const Expr *Init = VD->getAnyInitializer()) {
+          // Look through initializers like const char c[] = { "foo" }
+          if (const InitListExpr *InitList = dyn_cast<InitListExpr>(Init)) {
+            if (InitList->isStringLiteralInit())
+              Init = InitList->getInit(0)->IgnoreParenImpCasts();
+          }
           return SemaCheckStringLiteral(Init, Args, NumArgs,
                                         HasVAListArg, format_idx, firstDataArg,
                                         Type, /*inFunctionCall*/false);
+        }
       }
 
       // For vprintf* functions (i.e., HasVAListArg==true), we add a
index a9a040fdc031cb5a2034a433aa26950a9082a7b1..afc9e9720ce176980a2037f26df9cff34827ace9 100644 (file)
@@ -500,6 +500,10 @@ void pr9751() {
   printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the argument}}
 
   printf("%a", (long double)0); // expected-warning{{format specifies type 'double' but the argument has type 'long double'}}
+
+  // Test braced char[] initializers.
+  const char kFormat18[] = { "%lld" }; // expected-note{{format string is defined here}}}
+  printf(kFormat18, 0); // expected-warning{{format specifies type}}
 }
 
 // PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx