[clang] [clang][bytecode] Only implicitly start lifetime of trivially-default-constructible union members (PR #149835)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 21 09:30:10 PDT 2025
================
@@ -25,11 +25,18 @@ using APSInt = llvm::APSInt;
namespace clang {
namespace interp {
+static bool hasTrivialDefaultCtorParent(const FieldDecl *FD) {
+ assert(FD);
+ assert(FD->getParent()->isUnion());
+ const auto *CXXRD = dyn_cast<CXXRecordDecl>(FD->getParent());
+ return !CXXRD || CXXRD->hasTrivialDefaultConstructor();
+}
+
static bool refersToUnion(const Expr *E) {
for (;;) {
if (const auto *ME = dyn_cast<MemberExpr>(E)) {
if (const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
- FD && FD->getParent()->isUnion())
+ FD && FD->getParent()->isUnion() && hasTrivialDefaultCtorParent(FD))
----------------
cor3ntin wrote:
Do you handle things like that?
```cpp
struct s{
union {
union {
int m;
};
};
};
```
https://github.com/llvm/llvm-project/pull/149835
More information about the cfe-commits
mailing list