[clang] [Clang] Fix confusing diagnostics after #233375 (PR #238681)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 22:04:32 PST 2026
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/238681
Fixes #238014
>From e8b6c486a595c5771ec40720735938ae38fe50b1 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Wed, 4 Nov 2026 14:02:38 +0800
Subject: [PATCH] [Clang] Fix confusing diagnostics after #233375
---
clang/lib/Sema/SemaExprCXX.cpp | 9 +++++++--
clang/test/SemaCXX/decltype.cpp | 21 +++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5d64b61a32ba2a..ff2df92469b7e4 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 45a4c4cf1ac864..21d89a881d416d 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 {
More information about the cfe-commits
mailing list