diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5965,7 +5965,7 @@ "excess elements in char array initializer">, InGroup; def err_initializer_string_for_char_array_too_long : Error< - "initializer-string for char array is too long">; + "initializer-string for char array is too long, array size is %0 but initializer has size %1 (including the null terminating character)">; def ext_initializer_string_for_char_array_too_long : ExtWarn< "initializer-string for char array is too long">, InGroup; diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -239,6 +239,7 @@ if (StrLength > CAT->getSize().getZExtValue()) S.Diag(Str->getBeginLoc(), diag::err_initializer_string_for_char_array_too_long) + << CAT->getSize().getZExtValue() << StrLength << Str->getSourceRange(); } else { // C99 6.7.8p14. diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp --- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp +++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp @@ -1,2 +1,3 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -char test1[1]="f"; // expected-error {{initializer-string for char array is too long}} +char test1[1]="f"; // expected-error {{initializer-string for char array is too long, array size is 1 but initializer has size 2 (including the null terminating character)}} +char test2[1]="";