[clang][bytecode] Fix non-defaulted union copy/move ctors#199394
Open
tbaederr wants to merge 1 commit into
Open
[clang][bytecode] Fix non-defaulted union copy/move ctors#199394tbaederr wants to merge 1 commit into
tbaederr wants to merge 1 commit into
Conversation
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThey are like regular record ctors. Full diff: https://github.com/llvm/llvm-project/pull/199394.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4d13cd7139f83..1e58d91861ad5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6856,8 +6856,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
return false;
bool IsUnion = R->isUnion();
- // Union copy and move ctors are special.
- if (IsUnion && Ctor->isCopyOrMoveConstructor()) {
+ // Default union copy and move ctors are special.
+ if (IsUnion && Ctor->isCopyOrMoveConstructor() && Ctor->isDefaulted()) {
LocOverrideScope<Emitter> LOS(this, SourceInfo{});
// No special case for NumFields == 0 here, so the Memcpy op
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 399c4c891be00..17d868325f1a7 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -386,6 +386,18 @@ namespace CopyCtor {
static_assert(y.a == 42, "");
static_assert(y.b == 42, ""); // both-error {{constant expression}} \
// both-note {{'b' of union with active member 'a'}}
+
+ /// Non-defaulted copy ctor.
+ union U2 {
+ int a;
+ constexpr U() : a(100) {}
+ constexpr U(const U &u) {
+ a = 20;
+ };
+ };
+ constexpr U u2;
+ constexpr U u22(u2);
+ static_assert(u22.a == 20);
}
namespace UnionInBase {
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
They are like regular record ctors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
They are like regular record ctors.