Skip to content

Commit 8b3d4bd

Browse files
authored
[clang] Remove hasValue() check in RecordExprEvaluator::VisitCXXConstructExpr() (llvm#154610)
When initializing an anonymous struct via an `IndirectFieldDecl`, we create an `APValue` for the struct, but we leave the fields uninitialized. This would later cause the `CXXConstructExpr` that initializes the anonymous struct member to not do anything since its `APValue` already had a value (but the member didn't). Just remove the check for an `APValue` that already has a value from `RecordExprEvaluator::VisitCXXConstructExpr()`. Fixes llvm#154567
1 parent ee55efc commit 8b3d4bd

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11045,10 +11045,6 @@ bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E,
1104511045

1104611046
bool ZeroInit = E->requiresZeroInitialization();
1104711047
if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) {
11048-
// If we've already performed zero-initialization, we're already done.
11049-
if (Result.hasValue())
11050-
return true;
11051-
1105211048
if (ZeroInit)
1105311049
return ZeroInitialization(E, T);
1105411050

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,3 +2645,19 @@ namespace GH150709 {
26452645
static_assert((e2[0].*mp)() == 1, ""); // expected-error {{constant expression}}
26462646
static_assert((g.*mp)() == 1, ""); // expected-error {{constant expression}}
26472647
}
2648+
2649+
namespace GH154567 {
2650+
struct T {
2651+
int i;
2652+
};
2653+
2654+
struct S {
2655+
struct { // expected-warning {{GNU extension}}
2656+
T val;
2657+
};
2658+
constexpr S() : val() {}
2659+
};
2660+
2661+
constexpr S s{};
2662+
static_assert(s.val.i == 0, "");
2663+
}

0 commit comments

Comments
 (0)