https://github.com/Serosh-commits created https://github.com/llvm/llvm-project/pull/207072
when BuildConvertedConstantExpression receives an expression that is already a RecoveryExpr, return it directly instead of wrapping it in another RecoveryExpr fixes #186656 and #202117 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] [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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
