https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/207072
From 1e46141a50fac27787966018522f09f32d22a082 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Wed, 1 Jul 2026 22:51:09 +0530 Subject: [PATCH 1/2] [clang] Prevent nested RecoveryExpr in BuildConvertedConstantExpression --- clang/lib/Sema/SemaOverload.cpp | 2 ++ clang/test/SemaCXX/gh186656.cpp | 7 +++++++ clang/test/SemaCXX/gh202117.cpp | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 clang/test/SemaCXX/gh186656.cpp create mode 100644 clang/test/SemaCXX/gh202117.cpp diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 11e771bc240f1..f088425e139cf 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6469,6 +6469,8 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, return ExprError(); if (From->containsErrors()) { + if (isa<RecoveryExpr>(From)) + return From; // The expression already has errors, so the correct cast kind can't be // determined. Use RecoveryExpr to keep the expected type T and mark the // result as invalid, preventing further cascading errors. diff --git a/clang/test/SemaCXX/gh186656.cpp b/clang/test/SemaCXX/gh186656.cpp new file mode 100644 index 0000000000000..227489833da1b --- /dev/null +++ b/clang/test/SemaCXX/gh186656.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +template <template <int> typename> struct S; +template <int, int = (foo<void, void>())> struct T; // expected-error {{use of undeclared identifier 'foo'}} +template <typename...> struct U; + +using V = U<S<T>>; diff --git a/clang/test/SemaCXX/gh202117.cpp b/clang/test/SemaCXX/gh202117.cpp new file mode 100644 index 0000000000000..7fd0fddf598a7 --- /dev/null +++ b/clang/test/SemaCXX/gh202117.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +template<template<decltype(foo())> typename T> struct S {}; // expected-error {{use of undeclared identifier 'foo'}} +template<int*> struct P; + +S<P> s; From e1f9d89f7455568a248d33454f41ec11a2d03418 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Fri, 10 Jul 2026 19:29:41 +0530 Subject: [PATCH 2/2] [clang] Avoid redundant RecoveryExpr for typed invalid CCE --- clang/lib/Sema/SemaOverload.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 6fc5428b48769..eafda32198f11 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -6499,8 +6499,9 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, return ExprError(); if (From->containsErrors()) { - if (isa<RecoveryExpr>(From)) + if (S.Context.hasSameType(From->getType(), T)) return From; + // The expression already has errors, so the correct cast kind can't be // determined. Use RecoveryExpr to keep the expected type T and mark the // result as invalid, preventing further cascading errors. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
