Repository navigation
Keep union active members when zero-initializing in constant evaluation [GH #618] - #615
jonatanlinden wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
AcknowlEDG review results updated for
CI success. |
0eabdab to
c66e8f6
Compare
|
AcknowlEDG review results updated for
CI success. |
…on. [GH edgcpp#618] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c66e8f6 to
f50906a
Compare
|
AcknowlEDG review results updated for
CI success. |
This addresses the issue described in discussion #537, I'll update the PR once it has gotten an issue.
Problem
In constant evaluation, assigning a value-initialized temporary to an object of class type,
x = R(), loses the active member of every union subobject. Reading the first union member afterwards is diagnosed as "invalid access to inactive member ... (no field is active)". Zero-initialization should make the first named member of each union active (n4868 [dcl.init.general]/6.3).Fix
In
interpret.c, callmark_complete_class_object_if_needed, beforeinit_subobject_to_zerozero-initializes each member. Now,init_subobject_to_zerois called first, even though the comment ofmark_complete_class_object_if_neededsays "must therefore be invoked before placing a result in the indicated storage, because that result could set the active field".Testing
tests/tests/regressions/constexpr-union-zero-init-assign.sft.cpp(fp,--c++20)x = R{},R x = R();, nested unions, and a derived class whose base has a union member are accepted as well.constexpr-union-zero-init-assign-negative.sft.cpp(fn,--c++20)Summary by CodeRabbit