Repository navigation
Union has no active member after assignment from a value-initialized temporary in constant evaluation #537
jonatanlinden
started this conversation in
Issue Triage - Compilation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
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).Reproducing Source Code
Command-line Options
cpfe --c++20 --no_code_gen
Type of Issue
[Front End] This code SHOULD compile with these options.
Additional Details
This breaks libc++'s constexpr
std::stringmove constructor, which does__str.__r_.first() = __rep();(__repis a struct holding an anonymous union).Expected: no diagnostics.
Observed:
x = R{}andR x = R();are accepted; only the assignment fromR()fails. That temporary has adik_zeroinitializer and is initialized withinit_subobject_to_zero.Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.All reactions