]> granicus.if.org Git - clang/commitdiff
Tweak r183791 so we don't print a note without a source location.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 11 Jun 2013 22:26:34 +0000 (22:26 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 11 Jun 2013 22:26:34 +0000 (22:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183803 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/Sema/designated-initializers.c

index 4d6eaa45c4125eaa2e1944f855744c47d5067285..427f8f4110086fdc9f5162f97fe6b87450e69638 100644 (file)
@@ -2102,7 +2102,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
       for (unsigned i = 0, e = StrLen; i != e; ++i) {
         llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
         Expr *Init = new (Context) IntegerLiteral(
-            Context, CodeUnit, PromotedCharTy, SourceLocation());
+            Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc());
         if (CharTy != PromotedCharTy)
           Init = ImplicitCastExpr::Create(Context, CharTy, CK_IntegralCast,
                                           Init, 0, VK_RValue);
@@ -2124,7 +2124,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
       for (unsigned i = 0, e = StrLen; i != e; ++i) {
         llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
         Expr *Init = new (Context) IntegerLiteral(
-            Context, CodeUnit, PromotedCharTy, SourceLocation());
+            Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc());
         if (CharTy != PromotedCharTy)
           Init = ImplicitCastExpr::Create(Context, CharTy, CK_IntegralCast,
                                           Init, 0, VK_RValue);
index c9a8482e85dba82dacb01cf57e6084354caa193d..36fa559f6f3704d93cbfaac7d57dd8fb5a5413f6 100644 (file)
@@ -277,3 +277,19 @@ struct ds ds2 = { { {
     .a = 0,
     .b = 1 // expected-error{{field designator 'b' does not refer to any field}}
 } } };
+
+// Check initializer override warnings overriding a character in a string
+struct overwrite_string_struct {
+  char L[6];
+  int M;
+} overwrite_string[] = {
+  { { "foo" }, 1 }, // expected-note {{previous initialization is here}}
+  [0].L[2] = 'x' // expected-warning{{initializer overrides prior initialization of this subobject}}
+};
+struct overwrite_string_struct2 {
+  char L[6];
+  int M;
+} overwrite_string2[] = {
+    { { "foo" }, 1 },
+    [0].L[4] = 'x' // no-warning
+  };