Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang]Avoid diagnose invalid consteval call for invalid function decl #68646

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Fix crash in evaluating ``constexpr`` value for invalid template function.
- Fix crash when evaluating an invalid immediate function template.

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 @@ -18409,6 +18409,8 @@ static void EvaluateAndDiagnoseImmediateInvocation(

HerrCai0907 marked this conversation as resolved.
Show resolved Hide resolved
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}}
Loading