[PATCH] D141283: [clang] Improve diagnostic for "initializer-string for char array is too long"
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 19 04:13:36 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1499cce2646c: [clang] Improve diagnostic for "initializer-string for char array is too long" (authored by evansmal, committed by tbaeder).
Changed prior to commit:
https://reviews.llvm.org/D141283?vs=488012&id=490456#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D141283/new/
https://reviews.llvm.org/D141283
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp
clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp
Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp
===================================================================
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp
+++ 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]="";
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ 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.
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5965,7 +5965,7 @@
"excess elements in char array initializer">,
InGroup<ExcessInitializers>;
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<ExcessInitializers>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141283.490456.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230119/8e97cc28/attachment-0001.bin>
More information about the cfe-commits
mailing list