https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127416
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Jason Merrill <[email protected]>: https://gcc.gnu.org/g:a382bed036aa5f58622fc7551734f6280d1476c9 commit r17-4750-ga382bed036aa5f58622fc7551734f6280d1476c9 Author: Jonas Hansen <[email protected]> Date: Tue Sep 29 18:37:25 2026 +0200 c++: Normalize character array initializers after folding [PR127416] The call to braced_lists_to_strings in store_init_value does not look through TARGET_EXPR. A constexpr aggregate initialized through one can therefore retain a character array CONSTRUCTOR after constant evaluation. The middle end then treats an element of that array as a single-character string, causing a false -Wformat-truncation warning for a bounded snprintf call that reads only the remaining array elements. Move the existing conversion after constant folding, next to replace_placeholders, so it sees the folded initializer while remaining before split_nonconstant_init. Add diagnostic and runtime regressions covering bounded reads, overreads, truncation, constexpr copy and mutation, templates, embedded nuls, and implicit zero initialization. gcc/cp/ChangeLog: PR tree-optimization/127416 * typeck2.cc (store_init_value): Move braced_lists_to_strings after constant folding. gcc/testsuite/ChangeLog: PR tree-optimization/127416 * g++.dg/warn/Wformat-truncation-nonstring.C: New test. * g++.dg/torture/constexpr-array-string.C: New test. Signed-off-by: Jonas Hansen <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
