From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id B2BB03958C09; Tue, 10 Aug 2021 16:07:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2BB03958C09 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10026] libstdc++: Fix common_reference for non-reference results [PR100894] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 15dcbe073abd7225e3bb1b793605269f11c0fb61 X-Git-Newrev: 0e54986854831a4c66b308f98aff949ca7d3ce84 Message-Id: <20210810160719.B2BB03958C09@sourceware.org> Date: Tue, 10 Aug 2021 16:07:19 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Aug 2021 16:07:19 -0000 https://gcc.gnu.org/g:0e54986854831a4c66b308f98aff949ca7d3ce84 commit r10-10026-g0e54986854831a4c66b308f98aff949ca7d3ce84 Author: Jonathan Wakely Date: Mon Jun 14 20:31:00 2021 +0100 libstdc++: Fix common_reference for non-reference results [PR100894] The result of COMMON-REF(A&, B&&) where they have no common reference type should be ill-formed. Our implementation fails to check that the COMMON-REF result is a reference, so is well-formed when it shouldn't be. This means that common_reference uses that result when it shouldn't do. The fix is to reject the result of COMMON-REF(A, B) if it's not a reference, so that common_reference falls through to the next case, which uses COND-RES, which yields the correct non-reference result. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/100894 * include/std/type_traits (__common_ref_impl): Only use the type if it's a reference. * testsuite/20_util/common_reference/100894.cc: New test. (cherry picked from commit c37b5ddcc88e0cc0f6a4ad609eda51021df0f6bb) Diff: --- libstdc++-v3/include/std/type_traits | 12 +++++++++--- libstdc++-v3/testsuite/20_util/common_reference/100894.cc | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index c62dc72d3d7..cc34f82a31d 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3307,11 +3307,17 @@ template template using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type; + // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &) + template + using __condres_cvref + = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>; + // If A and B are both lvalue reference types, ... template - struct __common_ref_impl<_Xp&, _Yp&, - __void_t<__cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>>> - { using type = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>; }; + struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>> + : enable_if>, + __condres_cvref<_Xp, _Yp>> + { }; // let C be remove_reference_t&& template diff --git a/libstdc++-v3/testsuite/20_util/common_reference/100894.cc b/libstdc++-v3/testsuite/20_util/common_reference/100894.cc new file mode 100644 index 00000000000..5e144768002 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/common_reference/100894.cc @@ -0,0 +1,9 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// PR libstdc++/100894 - common_reference implementation seems to be wrong + +#include + +struct A {}; +struct B { B(A); }; +static_assert( std::is_same_v, B> );