diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2011-04-11 00:23:45 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2011-04-11 00:23:45 +0000 |
| commit | 554eba9c087371a02ac596178a57dca77c1f7a42 (patch) | |
| tree | b0821df21ddf89813660c8d43f682afc90e570b5 /clang/lib/Sema | |
| parent | 35a9c3cd7216f4f9ca7d632ab449d4caf1653624 (diff) | |
| download | bcm5719-llvm-554eba9c087371a02ac596178a57dca77c1f7a42.tar.gz bcm5719-llvm-554eba9c087371a02ac596178a57dca77c1f7a42.zip | |
PR9669: implement correct checking for [dcl.init.string]p2.
llvm-svn: 129260
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 0f8d4ddc336..1dff64e8557 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -92,13 +92,22 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT, const ConstantArrayType *CAT = cast<ConstantArrayType>(AT); - // C99 6.7.8p14. We have an array of character type with known size. However, + // We have an array of character type with known size. However, // the size may be smaller or larger than the string we are initializing. // FIXME: Avoid truncation for 64-bit length strings. - if (StrLength-1 > CAT->getSize().getZExtValue()) - S.Diag(Str->getSourceRange().getBegin(), - diag::warn_initializer_string_for_char_array_too_long) - << Str->getSourceRange(); + if (S.getLangOptions().CPlusPlus) { + // [dcl.init.string]p2 + if (StrLength > CAT->getSize().getZExtValue()) + S.Diag(Str->getSourceRange().getBegin(), + diag::err_initializer_string_for_char_array_too_long) + << Str->getSourceRange(); + } else { + // C99 6.7.8p14. + if (StrLength-1 > CAT->getSize().getZExtValue()) + S.Diag(Str->getSourceRange().getBegin(), + diag::warn_initializer_string_for_char_array_too_long) + << Str->getSourceRange(); + } // Set the type to the actual size that we are initializing. If we have // something like: |

