Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11045,10 +11045,6 @@ bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E,

bool ZeroInit = E->requiresZeroInitialization();
if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) {
// If we've already performed zero-initialization, we're already done.
if (Result.hasValue())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this code do nothing then? It looks like this check came in with e637cbe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it's working correctly, it allows skipping work zero-initializing something that's already zero-initialized, I think. But that assumes we maintain an invariant about exactly when values are absent, vs. uninitialized. We don't maintain that invariant for anonymous structs. (We probably could, but it's a little tricky to implement correctly for nested anonymous structs.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, maybe worth a FIXME, probably not a huge win though.

return true;

if (ZeroInit)
return ZeroInitialization(E, T);

Expand Down
16 changes: 16 additions & 0 deletions clang/test/SemaCXX/constant-expression-cxx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2645,3 +2645,19 @@ namespace GH150709 {
static_assert((e2[0].*mp)() == 1, ""); // expected-error {{constant expression}}
static_assert((g.*mp)() == 1, ""); // expected-error {{constant expression}}
}

namespace GH154567 {
struct T {
int i;
};

struct S {
struct { // expected-warning {{GNU extension}}
T val;
};
constexpr S() : val() {}
};

constexpr S s{};
static_assert(s.val.i == 0, "");
}