Skip to content

Commit e488fe5

Browse files
committed
[clang][Interp] Fix non-initializing MemberExprs
We need to create a value for them, do that via visit()
1 parent 69d4890 commit e488fe5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,13 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
11571157
if (DiscardResult)
11581158
return this->discard(Base);
11591159

1160-
if (!this->delegate(Base))
1161-
return false;
1160+
if (Initializing) {
1161+
if (!this->delegate(Base))
1162+
return false;
1163+
} else {
1164+
if (!this->visit(Base))
1165+
return false;
1166+
}
11621167

11631168
// Base above gives us a pointer on the stack.
11641169
// TODO: Implement non-FieldDecl members.

clang/test/AST/Interp/cxx03.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -std=c++03 -verify=expected,both %s -fexperimental-new-constant-interpreter
2+
// RUN: %clang_cc1 -std=c++03 -verify=ref,both %s
3+
4+
namespace NonInitializingMemberExpr {
5+
struct NonLit {
6+
NonLit() : value(0) {}
7+
int value;
8+
};
9+
__attribute__((require_constant_initialization)) const int &nl_subobj_ref = NonLit().value; // both-error {{variable does not have a constant initializer}} \
10+
// both-note {{required by}} \
11+
// both-note {{subexpression not valid}}
12+
}

0 commit comments

Comments
 (0)