-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Conversation
Fixes:#68542 It is meaningless to diagnoise further error for a invalid function declaration.
@llvm/pr-subscribers-clang Author: Congcong Cai (HerrCai0907) ChangesFixes:#68542 Full diff: https://github.com/llvm/llvm-project/pull/68646.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c5f96eebd04165..2e01b82b13d819e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
FD = Call->getConstructor();
else if (auto *Cast = dyn_cast<CastExpr>(InnerExpr))
FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction());
-
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..bc94fffe5de289d
--- /dev/null
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+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'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 'f<int>' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be initialized by a constant expression}}
\ No newline at end of file
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a release note, plus a couple nits. Otherwise LGTM!
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix crash in evaluating ``constexpr`` value for invalid template function. | |
- Fix crash when evaluating an invalid immediate function template. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to work on that and figured the fix would be along those lines! Glad you got to it first, thanks!
The changes look great
Fixes:#68542
It is meaningless to diagnose further error for a invalid function declaration.