Issue 207941
Summary initializer-string for char array is too long should be a warning in C++ mode when array size matches string length without null terminator
Labels new issue
Assignees
Reporter bnjmnjrk
    # observation
```
echo -e '#include <unistd.h>\nint main() { char buffer[2] = "hi"; write(STDOUT_FILENO, buffer, 2); }' > test.c
zig cc test.c
./a.out
mv test.c test.c++
zig c++ test.c++
```
This compiles fine in C, but is a hard error in C++:

> test.c++:2:31: error: initializer-string for char array is too long, array size is 2 but initializer has size 3 (including the null terminating character)

Forcing people to change to {'h','i'} or cursed casts everywhere reduces readability.

# expectation
Make this a work like in C, or add a specific flag like -Wno-initializer-string-too-long.

# versions
```
$ zig cc --version
clang version 21.1.0
Target: x86_64-unknown-linux6.17.0-gnu2.39.0
Thread model: posix
InstalledDir: zig-x86_64-linux-0.16.0
$ zig c++ --version
clang version 21.1.0
Target: x86_64-unknown-linux6.17.0-gnu2.39.0
Thread model: posix
InstalledDir: zig-x86_64-linux-0.16.0
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to