diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ea737fdb5fdad..31f4844f22ed3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -358,6 +358,8 @@ Bug Fixes in This Version Fixes (`#67690 `_) - Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` cannot be used with ``Release`` mode builds. (`#68237 `_). +- Fix crash in evaluating ``constexpr`` value for invalid template function. + Fixes (`#68542 `_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9c5f96eebd041..7ede275bb5a05 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -18409,6 +18409,8 @@ static void EvaluateAndDiagnoseImmediateInvocation( assert(FD && FD->isImmediateFunction() && "could not find an immediate function in this expression"); + if (FD->isInvalidDecl()) + return; SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call) << FD << FD->isConsteval(); if (auto Context = diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp new file mode 100644 index 0000000000000..fc767a78c8b00 --- /dev/null +++ b/clang/test/SemaCXX/PR68542.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s + +struct S { + int e; +}; + +template +consteval int get_format() { + return nullptr; // expected-error{{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}} +} + +template +constexpr S f(T) noexcept { + return get_format(); // expected-error{{no viable conversion from returned value of type 'int' to function return type 'S'}} +} + +constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be initialized by a constant expression}} +// expected-note@-1{{in instantiation of function template specialization 'f' requested here}} +// expected-note@3{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}} +// expected-note@3{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}