[clang] [Clang] Fix confusing diagnostics after #233375 (PR #238681)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 22:05:10 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Younan Zhang (zyn0217)
<details>
<summary>Changes</summary>
Fixes #<!-- -->238014
---
Full diff: https://github.com/llvm/llvm-project/pull/238681.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+7-2)
- (modified) clang/test/SemaCXX/decltype.cpp (+21)
``````````diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5d64b61a32ba2..ff2df92469b7e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6927,8 +6927,13 @@ ExprResult Sema::ActOnDecltypeExpression(Expr *E) {
ExpressionEvaluationContextRecord::EK_Decltype &&
"not in a decltype expression");
- // Give up here so we don't try to evaluate it later.
- if (isa<RecoveryExpr>(E))
+ // RecoveryExpr is always instantiation-dependent regardless of its
+ // type. If the type is essentially non-dependent, we continue to build
+ // a dependent decltype expression to avoid confusing diagnostics with wrong
+ // type. If the type is dependent, we will recover with int.
+ // FIXME: Maybe RecoveryExpr shouldn't be always instantiation-dependent, but
+ // in https://reviews.llvm.org/D83213 we chose so.
+ if (isa<RecoveryExpr>(E) && E->isTypeDependent())
return ExprError();
ExprResult Result = CheckPlaceholderExpr(E);
diff --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp
index 45a4c4cf1ac86..21d89a881d416 100644
--- a/clang/test/SemaCXX/decltype.cpp
+++ b/clang/test/SemaCXX/decltype.cpp
@@ -167,6 +167,27 @@ static_assert(A<int>().f<int>() != 0, ""); // expected-error {{static assertion
}
+namespace GH238014 {
+
+void foo(int); // expected-note {{candidate function}}
+void extract(int*);
+
+template <typename T>
+void test() {
+ using Type = decltype(foo(T{}));
+ // expected-error at -1 {{no matching function for call to 'foo'}}
+
+ // The RecoveryExpr is always considered as instantiation dependent so we stopped here.
+ extract(Type{});
+}
+
+struct Bar {};
+
+void run() { test<Bar>(); } // expected-note-re {{instantiation {{.*}} requested here}}
+
+}
+
+
#if __cplusplus >= 201703L
namespace GH160497 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/238681
More information about the cfe-commits
mailing list