This patch improves the diagnostic message "initializer-string for char array is too long"
by specifying an expected array length and by indicating that the initializer string implicitly
includes the null terminator.
Fixes #58829
Differential D141283
[clang] Improve diagnostic for "initializer-string for char array is too long" evansmal on Jan 9 2023, 7:11 AM. Authored by
Details
This patch improves the diagnostic message "initializer-string for char array is too long" Fixes #58829
Diff Detail
Event TimelineComment Actions Thank you for this diagnostic fix, please make sure you update clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp.
Comment Actions @shafik I noticed that there are also some tests in: clang/test/SemaCXX/pascal-strings.cpp, clang/test/Sema/array-init.c, and clang/test/Sema/format-strings.c that also check for this diagnostic. I assume these should also be updated? EDIT: It seems that git-clang-format is failing for the build. Running it re-formats most of clang/lib/Sema/SemaInit.cpp - can I commit these changes here or should I open a seperate PR for that? Comment Actions When grepping clang/test/ for "for char array is too long", I get a bunch of other hits for this diagnostic, are the those tests not failing for you (e.g. clang/test/Sema/array-init.c:149)? Comment Actions @tbaeder Yeah, the tests don't fail for me. I can update them, but I'm unsure how to tell if they're working properly. Comment Actions LGTM
Comment Actions Hi @shafik! Thanks for the review. I don't have commit access and am unsure what I should do to get this committed. Can you let me know what I need to do next? |
Note. we are allowed to initialize with a string-literal that is smaller than the array size so maybe something along the lines of array size is %0 but initializer has size %1