Fixes constexpr crash with nested empty objects.
This commit prevents a crash in constexpr evaluation when dealing with nested empty objects by avoiding premature calls to `get_or_insert_ctor_field`.
This commit addresses a crash that occurred during constexpr evaluation when an empty object contained a subobject that also required initialization. The issue stemmed from incorrect handling of constructor contexts during the evaluation of bare aggregates. Specifically, the cxx_eval_bare_aggregate function was calling get_or_insert_ctor_field with a null constructor context in certain scenarios, leading to a crash. The fix avoids this premature call, preventing the crash. New test cases g++.dg/cpp2a/no_unique_address17.C and g++.dg/cpp2a/no_unique_address18.C have been added.
In Details
The cxx_eval_bare_aggregate function is responsible for evaluating aggregate initialization in constexpr contexts. This patch addresses a case where nested empty objects (due to [[no_unique_address]]) caused issues with constructor context management, leading to a crash in get_or_insert_ctor_field. This fix is similar to the one provided for c++/125315. The interaction with TARGET_EXPR and the handling of empty classes are key to understanding this issue.
For Context
In C++, constexpr allows certain expressions to be evaluated at compile time, enabling optimizations and compile-time checking. This commit fixes a bug in the compiler's constexpr evaluation logic related to nested empty objects (objects that don't occupy any memory). The compiler was crashing when trying to initialize such objects in specific scenarios. This patch ensures that the compiler can correctly handle these cases, allowing programs to use constexpr more reliably.