[clang] 19d1da5 - [clang]Avoid diagnose invalid consteval call for invalid function decl (#68646)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 00:32:15 PDT 2023
Author: Congcong Cai
Date: 2023-10-10T15:32:10+08:00
New Revision: 19d1da59dcdea46d30d93a48c389856e89c57b5d
URL: https://github.com/llvm/llvm-project/commit/19d1da59dcdea46d30d93a48c389856e89c57b5d
DIFF: https://github.com/llvm/llvm-project/commit/19d1da59dcdea46d30d93a48c389856e89c57b5d.diff
LOG: [clang]Avoid diagnose invalid consteval call for invalid function decl (#68646)
Fixes:#68542
It‘s meaningless to diagnose further error for invalid function
declaration.
Added:
clang/test/SemaCXX/PR68542.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96928e98bcee156..9c320bc8b35d23d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 15e2a7978f6b723..cf45fc388083ce6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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 =
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
new file mode 100644
index 000000000000000..fc767a78c8b0013
--- /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<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 at -1{{in instantiation of function template specialization 'f<int>' requested here}}
+// expected-note at 3{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note at 3{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}
More information about the cfe-commits
mailing list