File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6856,8 +6856,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
68566856 return false ;
68576857 bool IsUnion = R->isUnion ();
68586858
6859- // Union copy and move ctors are special.
6860- if (IsUnion && Ctor->isCopyOrMoveConstructor ()) {
6859+ // Default union copy and move ctors are special.
6860+ if (IsUnion && Ctor->isCopyOrMoveConstructor () && Ctor-> isDefaulted () ) {
68616861 LocOverrideScope<Emitter> LOS (this , SourceInfo{});
68626862
68636863 // No special case for NumFields == 0 here, so the Memcpy op
Original file line number Diff line number Diff line change @@ -386,6 +386,18 @@ namespace CopyCtor {
386386 static_assert (y.a == 42 , " " );
387387 static_assert (y.b == 42 , " " ); // both-error {{constant expression}} \
388388 // both-note {{'b' of union with active member 'a'}}
389+
390+ // / Non-defaulted copy ctor.
391+ union U2 {
392+ int a;
393+ constexpr U2 () : a (100 ) {}
394+ constexpr U2 (const U2 &u) {
395+ a = 20 ;
396+ };
397+ };
398+ constexpr U2 u2;
399+ constexpr U2 u22 (u2);
400+ static_assert (u22.a == 20 , " " );
389401}
390402
391403namespace UnionInBase {
You can’t perform that action at this time.
0 commit comments