https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128108
Bug ID: 128108
Summary: uint16_t array missing nul terminator triggers
unsuppressable `unterminated-string-initialization`
warning
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: aiden at loroco dot tech
Target Milestone: ---
Created attachment 65939
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65939&action=edit
source code
Compiling the attached file results in an error complaining that the nonstring
attribute is ignored on "objects of type uint16_t[8]", while the use of said
uint16 array warns that we truncate the NUL terminator:
```
$ gcc -Werror -Wextra -o test testcase.c
testcase.c:9:9: error: ‘nonstring’ attribute ignored on objects of type
‘uint16_t[8]’ {aka ‘short unsigned int[8]’} [-Werror=attributes]
9 | uint16_t string[(sizeof(SOME_UTF16_STRING) / 2) - 1]
__attribute__((nonstring));
| ^~~~~~~~
testcase.c:4:27: error: initializer-string for array of ‘short unsigned int’
truncates NUL terminator but destination lacks ‘nonstring’ attribute (18 chars
into 16 available) [-Werror=unterminated-string-initialization]
4 | #define SOME_UTF16_STRING u"ABCD1234"
| ^~~~~~~~~~~
testcase.c:15:19: note: in expansion of macro ‘SOME_UTF16_STRING’
15 | .string = SOME_UTF16_STRING,
| ^~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```
I would expect that either the nonstring attribute would be applyable to uint16
arrays, or that the `unterminated-string-initialization` would not fire on the
array in the first place.
GCC details (stock Fedora 44 gcc):
```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,cobol,algol68,lto
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugzilla.redhat.com/ --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-16.2.1-build/gcc-16.2.1-20260819/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-tls=gnu2 --with-arch_32=i686
--build=x86_64-redhat-linux --with-build-config=bootstrap-lto
--enable-link-serialization=1 --disable-libssp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260819 (Red Hat 16.2.1-2) (GCC)
```