diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -198,6 +198,10 @@ - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes: (`#64171 `_). +- Fix a crash when an immediate invocation is not a constant expression + and appear in an implicit cast. + (`#64949 `_). + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -18352,15 +18352,17 @@ SemaRef.FailedImmediateInvocations.insert(CE); Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); if (auto *FunctionalCast = dyn_cast(InnerExpr)) - InnerExpr = FunctionalCast->getSubExpr(); + InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit(); FunctionDecl *FD = nullptr; if (auto *Call = dyn_cast(InnerExpr)) FD = cast(Call->getCalleeDecl()); else if (auto *Call = dyn_cast(InnerExpr)) FD = Call->getConstructor(); - else - llvm_unreachable("unhandled decl kind"); - assert(FD && FD->isImmediateFunction()); + else if (auto *Cast = dyn_cast(InnerExpr)) + FD = dyn_cast_or_null(Cast->getConversionFunction()); + + assert(FD && FD->isImmediateFunction && + "could not find an immediate function in this expression"); SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call) << FD << FD->isConsteval(); if (auto Context = diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp --- a/clang/test/SemaCXX/cxx2a-consteval.cpp +++ b/clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1103,3 +1103,23 @@ // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}} } } + +namespace GH64949 { +struct f { + int g; // expected-note {{subobject declared here}} + constexpr ~f() {} +}; +class h { + +public: + consteval h(char *) {} + consteval operator int() const { return 1; } + f i; +}; + +void k() { (int)h{nullptr}; } +// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}} +// expected-note@-2 {{subobject 'g' is not initialized}} + + +}