From: Aiden Jeffrey <[email protected]>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128108

gcc/c/ChangeLog:

        * c-typeck.cc (digest_init):

gcc/testsuite/ChangeLog:

        * gcc.dg/Wunterminated-string-initialization.c:
---
This is a forge pull request published on the gcc-patches mailing list mailing 
list
as requested by aidenhjj via Sourceware Forge 
<[email protected]>.
Forge discussion: https://forge.sourceware.org/gcc/gcc/pulls/256

Get it locally using:
```
git fetch forge-upstream "+refs/versioned_pull/256/*:refs/versioned_pull/256/*"
git switch -c "pr-256-v1" "refs/versioned_pull/256/1/head"
```
Or, download the patch at: https://forge.sourceware.org/gcc/gcc/pulls/256.diff
Created on: 2026-10-23 17:21:53+00:00
Latest update: 2026-10-23 17:40:22+00:00
Changes: 2 changed files, 9 additions, 2 deletions
Head revision: gcc/gcc ref refs/pull/256/head commit 
ea1a708ef9966a4d88bf1997e5e8021a99228b25 
Base revision: gcc/gcc ref trunk commit 
8d3bac71a9433f90161a22dd13812457d32c2352 r17-5515-g8d3bac71a9433f
Merge base: 8d3bac71a9433f90161a22dd13812457d32c2352
Requested Reviewers: 

Changed files:
- M: gcc/c/c-typeck.cc
- M: gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c

 gcc/c/c-typeck.cc                                         | 3 ++-
 .../gcc.dg/Wunterminated-string-initialization.c          | 8 +++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 2d0200858331c..8f8af8753289c 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -10065,7 +10065,8 @@ digest_init (location_t init_loc, tree decl, tree type, 
tree init,
                                "is too long for C++ (%wu chars into %wu "
                                "available)", typ1, len, avail);
                  else if (warn_unterminated_string_initialization
-                          && get_attr_nonstring_decl (decl) == NULL_TREE)
+                          && get_attr_nonstring_decl (decl) == NULL_TREE
+                          && char_array)
                    warning_at (init_loc,
                                OPT_Wunterminated_string_initialization,
                                "initializer-string for array of %qT "
diff --git a/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c 
b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
index 5f25f02991976..a05a28660eeab 100644
--- a/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
+++ b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
@@ -2,6 +2,8 @@
 /* { dg-do compile } */
 /* { dg-options "-Wunterminated-string-initialization" } */
 
+#include <stdint.h>
+
 char a1[] = "a";
 char a2[1] = "a";      /* { dg-warning "initializer-string for array of 'char' 
truncates" } */
 char a2nonstring[1] __attribute__((nonstring)) = "a";
@@ -18,6 +20,8 @@ struct has_str {
   char tag2[4] __attribute__((nonstring));
   char tag3[4] __attribute__((nonstring));
   char tag4[4] __attribute__((nonstring));
+  uint16_t utf16_1[4];
+  uint16_t utf16_2[4];
   int b;
 };
 
@@ -29,5 +33,7 @@ struct has_str foo = {
   .tag1 = "AAA",
   .tag2 = "BBBB",
   .tag3 = "CCCCC",     /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
-  .tag4 = { 'D', 'D', 'D', 'D' }
+  .tag4 = { 'D', 'D', 'D', 'D' },
+  .utf16_1 = u"AAAA",
+  .utf16_1 = u"BBBBB" /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
 };
-- 
2.54.0

Reply via email to