diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e9a58289f6fc0..e36a7a0c0a717 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1157,8 +1157,13 @@ bool ByteCodeExprGen::VisitMemberExpr(const MemberExpr *E) { if (DiscardResult) return this->discard(Base); - if (!this->delegate(Base)) - return false; + if (Initializing) { + if (!this->delegate(Base)) + return false; + } else { + if (!this->visit(Base)) + return false; + } // Base above gives us a pointer on the stack. // TODO: Implement non-FieldDecl members. diff --git a/clang/test/AST/Interp/cxx03.cpp b/clang/test/AST/Interp/cxx03.cpp new file mode 100644 index 0000000000000..d30cbb2fd7a20 --- /dev/null +++ b/clang/test/AST/Interp/cxx03.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++03 -verify=expected,both %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++03 -verify=ref,both %s + +namespace NonInitializingMemberExpr { + struct NonLit { + NonLit() : value(0) {} + int value; + }; + __attribute__((require_constant_initialization)) const int &nl_subobj_ref = NonLit().value; // both-error {{variable does not have a constant initializer}} \ + // both-note {{required by}} \ + // both-note {{subexpression not valid}} +}