================
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunterminated-string-initialization
%s -x c
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunterminated-string-initialization
%s -x c++
+
+
+// In C, the following examples are fine:
+#if __cplusplus
+char foo[3] = "fo\0"; // expected-error {{initializer-string for char array is
too long, array size is 3 but initializer has size 4 (including the null
terminating character)}}
+
+struct S {
+ char buf[3];
+ char fub[3];
+} s = { "ba\0", "bo\0" }; // expected-error 2{{initializer-string for char
array is too long, array size is 3 but initializer has size 4 (including the
null terminating character)}}
+
+signed char scfoo[3] = "fo\0"; // expected-error {{initializer-string for char
array is too long, array size is 3 but initializer has size 4 (including the
null terminating character)}}
+unsigned char ucfoo[3] = "fo\0"; // expected-error {{initializer-string for
char array is too long, array size is 3 but initializer has size 4 (including
the null terminating character)}}
+
----------------
AaronBallman wrote:
Another test case that's good to add would be:
```
char c[1] = ""; // Okay
```
https://github.com/llvm/llvm-project/pull/143487
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits