Normalize character array initializers after folding
Character array initializers are now normalized after constant folding to prevent false warnings.
This change normalizes character array initializers after constant folding to resolve a false -Wformat-truncation warning. Previously, the conversion of braced lists to strings did not account for TARGET_EXPR, allowing character arrays within constexpr aggregates to retain a CONSTRUCTOR form. This led the compiler to incorrectly interpret array elements as single-character strings, triggering warnings for bounded snprintf calls. The fix moves the conversion to occur after constant folding, ensuring it sees the correctly folded initializer.
In Details
The store_init_value function in typeck2.cc previously called braced_lists_to_strings before constant folding. This commit moves the call to braced_lists_to_strings to after constant folding, alongside replace_placeholders. This ensures that initializers for character arrays within TARGET_EXPR are correctly processed after constant propagation, preventing misinterpretations by subsequent optimization passes and avoiding false positives like -Wformat-truncation.
- TARGET_EXPR
- A GCC internal representation for target-specific expressions, often used in constant evaluation.
- -Wformat-truncation
- A GCC warning flag that detects potential truncation of strings when using format string functions like snprintf.
- constexpr aggregate
- An aggregate type (like a struct or array) whose initialization can be performed at compile time.
- constant folding
- A compiler optimization that evaluates constant expressions at compile time rather than runtime.