diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index b52892cf69bfb..a322700fc0d22 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -27,10 +27,7 @@ Context::~Context() {} bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) { assert(Stk.empty()); - Function *Func = P->getFunction(FD); - if (!Func || !Func->hasBody()) - Func = Compiler(*this, *P).compileFunc(FD); - + const Function *Func = getOrCreateFunction(FD); if (!Func) return false; @@ -271,6 +268,7 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl, const Function *Context::getOrCreateFunction(const FunctionDecl *FD) { assert(FD); + FD = FD->getMostRecentDecl(); const Function *Func = P->getFunction(FD); bool IsBeingCompiled = Func && Func->isDefined() && !Func->isFullyCompiled(); bool WasNotDefined = Func && !Func->isConstexpr() && !Func->isDefined(); diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp index e478a0ddc4c14..b9327716d7b92 100644 --- a/clang/test/AST/ByteCode/cxx2a.cpp +++ b/clang/test/AST/ByteCode/cxx2a.cpp @@ -170,3 +170,12 @@ namespace TypeId { } static_assert(side_effects()); } + +consteval int f(int i); +constexpr bool test(auto i) { + return f(0) == 0; +} +consteval int f(int i) { + return 2 * i; +} +static_assert(test(42));