Skip to content

Commit 4881cbd

Browse files
authored
[clang][Interp] Fix MemberExpr initializing an existing value (#79973)
This is similar to c1ad363, but with the additional twist that initializing an existing value from a `MemberExpr` was not working correctly.
1 parent 41ea022 commit 4881cbd

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
11291129
if (DiscardResult)
11301130
return this->discard(Base);
11311131

1132-
if (!this->visit(Base))
1132+
if (!this->delegate(Base))
11331133
return false;
11341134

11351135
// Base above gives us a pointer on the stack.
@@ -1617,8 +1617,10 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
16171617
return this->emitGetPtrLocal(*LocalIndex, E);
16181618
}
16191619
} else {
1620+
const Expr *Inner = E->getSubExpr()->skipRValueSubobjectAdjustments();
1621+
16201622
if (std::optional<unsigned> LocalIndex =
1621-
allocateLocal(SubExpr, /*IsExtended=*/true)) {
1623+
allocateLocal(Inner, /*IsExtended=*/true)) {
16221624
if (!this->emitGetPtrLocal(*LocalIndex, E))
16231625
return false;
16241626
return this->visitInitializer(SubExpr);

clang/test/AST/Interp/cxx98.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ int NCI; // both-note {{declared here}}
3030
int NCIA[NCI]; // both-warning {{variable length array}} \
3131
// both-error {{variable length array}} \\
3232
// both-note {{read of non-const variable 'NCI'}}
33+
34+
35+
struct V {
36+
char c[1];
37+
banana V() : c("i") {} // both-error {{unknown type name 'banana'}} \
38+
// both-error {{constructor cannot have a return type}}
39+
};
40+
_Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}

clang/test/SemaCXX/pr72025.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only %s
2+
// RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only -fexperimental-new-constant-interpreter %s
23
struct V {
34
char c[2];
45
banana V() : c("i") {} // expected-error {{unknown type name}}

0 commit comments

Comments
 (0)