Skip to content

Commit 0e72952

Browse files
committed
[clang][Interp] Fix MemberExpr initializing an existing value
1 parent 5877949 commit 0e72952

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

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

1022-
if (!this->visit(Base))
1022+
if (!this->delegate(Base))
10231023
return false;
10241024

10251025
// Base above gives us a pointer on the stack.
@@ -1507,8 +1507,13 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
15071507
return this->emitGetPtrLocal(*LocalIndex, E);
15081508
}
15091509
} else {
1510+
SmallVector<const Expr *, 2> CommaLHSs;
1511+
SmallVector<SubobjectAdjustment, 2> Adjustments;
1512+
const Expr *Inner =
1513+
E->getSubExpr()->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
1514+
15101515
if (std::optional<unsigned> LocalIndex =
1511-
allocateLocal(SubExpr, /*IsExtended=*/true)) {
1516+
allocateLocal(Inner, /*IsExtended=*/true)) {
15121517
if (!this->emitGetPtrLocal(*LocalIndex, E))
15131518
return false;
15141519
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)