diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2013-06-11 22:26:34 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2013-06-11 22:26:34 +0000 |
| commit | 6cc05f7f01b22d279ca4c95690dd6fe8df626579 (patch) | |
| tree | 8d736e593210458f8914af8c0525b532dca21497 | |
| parent | 5c50a16ee01911ae23cbc7f1caf6c909b8708ec4 (diff) | |
| download | bcm5719-llvm-6cc05f7f01b22d279ca4c95690dd6fe8df626579.tar.gz bcm5719-llvm-6cc05f7f01b22d279ca4c95690dd6fe8df626579.zip | |
Tweak r183791 so we don't print a note without a source location.
llvm-svn: 183803
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 4 | ||||
| -rw-r--r-- | clang/test/Sema/designated-initializers.c | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 4d6eaa45c41..427f8f41100 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -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); diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c index c9a8482e85d..36fa559f6f3 100644 --- a/clang/test/Sema/designated-initializers.c +++ b/clang/test/Sema/designated-initializers.c @@ -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 + }; |

