diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 10e32d9b7bcf3..f31755e72e8de 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1030,14 +1030,17 @@ bool ByteCodeExprGen::VisitSubstNonTypeTemplateParmExpr( template bool ByteCodeExprGen::VisitConstantExpr(const ConstantExpr *E) { - // Try to emit the APValue directly, without visiting the subexpr. - // This will only fail if we can't emit the APValue, so won't emit any - // diagnostics or any double values. std::optional T = classify(E->getType()); - if (T && E->hasAPValueResult() && - this->visitAPValue(E->getAPValueResult(), *T, E)) - return true; + if (T && E->hasAPValueResult()) { + // Try to emit the APValue directly, without visiting the subexpr. + // This will only fail if we can't emit the APValue, so won't emit any + // diagnostics or any double values. + if (DiscardResult) + return true; + if (this->visitAPValue(E->getAPValueResult(), *T, E)) + return true; + } return this->delegate(E->getSubExpr()); } diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp index 50a7c02925878..0af553a77892e 100644 --- a/clang/test/AST/Interp/cxx20.cpp +++ b/clang/test/AST/Interp/cxx20.cpp @@ -752,3 +752,16 @@ namespace TryCatch { } static_assert(foo() == 11); } + +namespace IgnoredConstantExpr { + consteval int immediate() { return 0;} + struct ReferenceToNestedMembers { + int m; + int a = ((void)immediate(), m); + int b = ((void)immediate(), this->m); + }; + struct ReferenceToNestedMembersTest { + void* m = nullptr; + ReferenceToNestedMembers j{0}; + } test_reference_to_nested_members; +} diff --git a/clang/test/SemaCXX/cxx11-default-member-initializers.cpp b/clang/test/SemaCXX/cxx11-default-member-initializers.cpp index 9c18c73be8f68..dd8e9c6b7fc11 100644 --- a/clang/test/SemaCXX/cxx11-default-member-initializers.cpp +++ b/clang/test/SemaCXX/cxx11-default-member-initializers.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c++11 -verify %s -pedantic +// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic -fexperimental-new-constant-interpreter // RUN: %clang_cc1 -std=c++20 -verify %s -pedantic +// RUN: %clang_cc1 -std=c++20 -verify %s -pedantic -fexperimental-new-constant-interpreter namespace PR31692 {