From e5d123bfd6ec7d59ae7cae9b6b3a65d0145c2fa1 Mon Sep 17 00:00:00 2001 From: luka Date: Sat, 5 Sep 2026 01:54:27 +0800 Subject: [PATCH] : Fix C2382 when mixing #include with import std; _Zip_iterator_sentinel_equal's noexcept-specifier contains a fold expression, which the compiler fails to match as equivalent between the textually-included and module-imported declarations, emitting C2382. Extract it into a variable template so both declarations reference a simple name, which is trivially matched. Fixes #6121 --- stl/inc/ranges | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stl/inc/ranges b/stl/inc/ranges index 8317ea26049..7e42f98c7e7 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -7140,14 +7140,23 @@ namespace ranges { return _Get_smallest_distance_closure(index_sequence_for<_LHSTupleTypes...>{}); } + // Work around C2382 when mixing #include with import std;: a noexcept fold expression prevents + // the compiler from matching the textual and module declarations, while a variable template is trivially matched. + template + inline constexpr bool _Zip_iterator_sentinel_equal_is_nothrow = false; + + template + inline constexpr bool _Zip_iterator_sentinel_equal_is_nothrow, tuple<_RHSTupleTypes...>> = + (noexcept(_STD declval() == _STD declval()) && ...); + template requires (sizeof...(_LHSTupleTypes) == sizeof...(_RHSTupleTypes)) _NODISCARD constexpr bool _Zip_iterator_sentinel_equal( const tuple<_LHSTupleTypes...>& _Lhs_tuple, const tuple<_RHSTupleTypes...>& _Rhs_tuple) - noexcept((noexcept(_STD declval() == _STD declval()) && ...)) { + noexcept(_Zip_iterator_sentinel_equal_is_nothrow, tuple<_RHSTupleTypes...>>) { const auto _Evaluate_equality_closure = [&_Lhs_tuple, &_Rhs_tuple](index_sequence<_Indices...>) noexcept( - (noexcept(_STD declval() == _STD declval()) &&...)) { + _Zip_iterator_sentinel_equal_is_nothrow, tuple<_RHSTupleTypes...>>) { return ((_STD get<_Indices>(_Lhs_tuple) == _STD get<_Indices>(_Rhs_tuple)) || ... || false); };