c++: Fix incorrect array initialization with mixed static/dynamic parts
Corrects array initialization where parts are declared static and others dynamic, preventing loss of initializer data.
This commit fixes a bug in C++ array initialization that occurred when an array had both static (constant) and dynamic (non-constant) initializers. A recent simplification in checking initializers led to the dynamic part being processed, but then the static part was incorrectly overwritten and lost. The fix prevents this loss of data by ensuring the static initializer is preserved when both types of initializers are present.
In Details
Fixes a wrong-code error in check_initializer where, after r17-1661, an array with both static and dynamic initializers would lose the static portion. Previously build_vec_init would signal completion by returning true, causing split_nonconstant_init to discard the DECL_INITIAL. This patch preserves the DECL_INITIAL set by build_vec_init.
- initializer
- Code that assigns an initial value to a variable or object when it is declared.
- static initializer
- An initializer that uses constant values, which can be placed in read-only memory or directly initialized in the binary.
- dynamic initializer
- An initializer that requires runtime computation or uses non-constant values, often involving function calls or complex expressions.
- DECL_INITIAL
- GCC's internal representation for the initializer associated with a declaration (a variable or object).