Author: Timm Bäder Date: 2024-02-19T11:57:01+01:00 New Revision: e488fe5a97ba8da9be31926c219932db92298f21
URL: https://github.com/llvm/llvm-project/commit/e488fe5a97ba8da9be31926c219932db92298f21 DIFF: https://github.com/llvm/llvm-project/commit/e488fe5a97ba8da9be31926c219932db92298f21.diff LOG: [clang][Interp] Fix non-initializing MemberExprs We need to create a value for them, do that via visit() Added: clang/test/AST/Interp/cxx03.cpp Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e9a58289f6fc07..e36a7a0c0a7175 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1157,8 +1157,13 @@ bool ByteCodeExprGen<Emitter>::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 00000000000000..d30cbb2fd7a201 --- /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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits