[clang] 70219c2 - [Clang] Fix confusing diagnostics after #233375 (#238681)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 23:50:18 PST 2026


Author: Younan Zhang
Date: 2026-11-10T07:50:12Z
New Revision: 70219c2825d8cccdcd0d69b5b5fa962f356ee47e

URL: https://github.com/llvm/llvm-project/commit/70219c2825d8cccdcd0d69b5b5fa962f356ee47e
DIFF: https://github.com/llvm/llvm-project/commit/70219c2825d8cccdcd0d69b5b5fa962f356ee47e.diff

LOG: [Clang] Fix confusing diagnostics after #233375 (#238681)

Fixes #238014

Added: 
    

Modified: 
    clang/lib/Sema/SemaExprCXX.cpp
    clang/test/SemaCXX/decltype.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5d64b61a32ba2..576393d459406 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6927,8 +6927,12 @@ 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.
+  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 {
 


        


More information about the cfe-commits mailing list