[clang] [-Wunterminated-string-initialization] Handle C string literals ending with explicit '\0' (PR #143487)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 16 05:32:29 PDT 2025
================
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunterminated-string-initialization %s -x c
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx,expected -Wunterminated-string-initialization %s -x c++
+
+
+#ifdef __cplusplus
+// C++ is stricter so the following cases should be warned about:
----------------
AaronBallman wrote:
I think we want the same test cases between C and C++, the only thing that should be different is the expected diagnostic comments. e.g.,
```
char foo3[3] = "fo\0"; // cxx-error {{initializer-string for char array is too long, array size is 3 but initializer has size 4 (including the null terminating character)}}
```
is fine in C because the diagnostic will only be checked in C++ mode.
The only code that should be in the `#if` would be things like the typedefs for C.
https://github.com/llvm/llvm-project/pull/143487
More information about the cfe-commits
mailing list