Skip to content

Commit

Permalink
[clang]Avoid diagnose invalid consteval call for invalid function decl (
Browse files Browse the repository at this point in the history
#68646)

Fixes:#68542
It‘s meaningless to diagnose further error for invalid function
declaration.
  • Loading branch information
HerrCai0907 authored Oct 10, 2023
1 parent aa5158c commit 19d1da5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ Bug Fixes in This Version
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
- Fix crash in evaluating ``constexpr`` value for invalid template function.
Fixes (`#68542 <https://github.com/llvm/llvm-project/issues/68542>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18408,6 +18408,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 =
Expand Down
20 changes: 20 additions & 0 deletions clang/test/SemaCXX/PR68542.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s

struct S {
int e;
};

template<class T>
consteval int get_format() {
return nullptr; // expected-error{{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}}
}

template<class T>
constexpr S f(T) noexcept {
return get_format<T>(); // 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<int>' 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}}

0 comments on commit 19d1da5

Please sign in to comment.