Skip to content

Commit 19d1da5

Browse files
authored
[clang]Avoid diagnose invalid consteval call for invalid function decl (#68646)
Fixes:#68542 It‘s meaningless to diagnose further error for invalid function declaration.
1 parent aa5158c commit 19d1da5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ Bug Fixes in This Version
375375
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
376376
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
377377
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
378+
- Fix crash in evaluating ``constexpr`` value for invalid template function.
379+
Fixes (`#68542 <https://github.com/llvm/llvm-project/issues/68542>`_)
378380

379381
Bug Fixes to Compiler Builtins
380382
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18408,6 +18408,8 @@ static void EvaluateAndDiagnoseImmediateInvocation(
1840818408

1840918409
assert(FD && FD->isImmediateFunction() &&
1841018410
"could not find an immediate function in this expression");
18411+
if (FD->isInvalidDecl())
18412+
return;
1841118413
SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
1841218414
<< FD << FD->isConsteval();
1841318415
if (auto Context =

clang/test/SemaCXX/PR68542.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
2+
3+
struct S {
4+
int e;
5+
};
6+
7+
template<class T>
8+
consteval int get_format() {
9+
return nullptr; // expected-error{{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}}
10+
}
11+
12+
template<class T>
13+
constexpr S f(T) noexcept {
14+
return get_format<T>(); // expected-error{{no viable conversion from returned value of type 'int' to function return type 'S'}}
15+
}
16+
17+
constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be initialized by a constant expression}}
18+
// expected-note@-1{{in instantiation of function template specialization 'f<int>' requested here}}
19+
// expected-note@3{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}}
20+
// expected-note@3{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}

0 commit comments

Comments
 (0)