public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong
@ 2021-06-03 16:35 hewillk at gmail dot com
  2021-06-14 17:25 ` [Bug libstdc++/100894] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hewillk at gmail dot com @ 2021-06-03 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

            Bug ID: 100894
           Summary: The std::common_reference implementation seems to be
                    wrong
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

In [meta#trans.other-6.3.1], the standard specifies "If T1 and T2 are reference
types and COMMON-REF(T1, T2) is well-formed, then the member typedef type
denotes that type", where COMMON-REF is defined in [meta#trans.other-3.5]: "If
A and B are both lvalue reference types, COMMON-REF(A, B) is COND-RES(COPYCV(X,
Y) &, COPYCV(​ Y, X) &) if that type exists and is a reference type."

libstdc++ does not check that COMMON-REF(A, B) must be a reference type, which
will lead to incorrect determination of the common reference type according to
bullet 1 in the following cases.

https://godbolt.org/z/7Mc7jjesK

#include <concepts>

struct A {};
struct B { B(A); };
static_assert(
  std::same_as<
  std::common_reference_t<A&, B&&>, B>);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
@ 2021-06-14 17:25 ` redi at gcc dot gnu.org
  2021-06-14 19:30 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-14 17:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-06-14

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
  2021-06-14 17:25 ` [Bug libstdc++/100894] " redi at gcc dot gnu.org
@ 2021-06-14 19:30 ` redi at gcc dot gnu.org
  2021-06-14 20:17 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-14 19:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.4

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For the next time I can't figure out how this works ...

COMMON-REF(A&, B&&) is COMMON-REF(B&&, A&) which is COMMON-REF(const B&, A&)
which is COND-RES(const B&, const A&) if that is a reference type, ill-formed
otherwise. Since the COND-RES type is just B, it's ill-formed.

That means that common_reference_t<A&, B&&> uses the third bullet, so it's
COND-RES(A&, B&&) which is B.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
  2021-06-14 17:25 ` [Bug libstdc++/100894] " redi at gcc dot gnu.org
  2021-06-14 19:30 ` redi at gcc dot gnu.org
@ 2021-06-14 20:17 ` cvs-commit at gcc dot gnu.org
  2021-06-14 21:49 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-14 20:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:c37b5ddcc88e0cc0f6a4ad609eda51021df0f6bb

commit r12-1437-gc37b5ddcc88e0cc0f6a4ad609eda51021df0f6bb
Author: Jonathan Wakely <jwakely@redhat.com>
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 not be a reference. The implementation of COMMON-REF fails
    to check that the 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.

    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 a non-reference result.

    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/100894
            * include/std/type_traits (__common_ref_impl<X&, Y&>): Only
            use the type if it's a reference.
            * testsuite/20_util/common_reference/100894.cc: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2021-06-14 20:17 ` cvs-commit at gcc dot gnu.org
@ 2021-06-14 21:49 ` cvs-commit at gcc dot gnu.org
  2021-08-10 16:07 ` cvs-commit at gcc dot gnu.org
  2021-08-10 16:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-14 21:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:3ae416e0a77a000b536171dbe06c3c2d136fb8e1

commit r11-8572-g3ae416e0a77a000b536171dbe06c3c2d136fb8e1
Author: Jonathan Wakely <jwakely@redhat.com>
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 <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/100894
            * include/std/type_traits (__common_ref_impl<X&, Y&>): Only
            use the type if it's a reference.
            * testsuite/20_util/common_reference/100894.cc: New test.

    (cherry picked from commit c37b5ddcc88e0cc0f6a4ad609eda51021df0f6bb)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2021-06-14 21:49 ` cvs-commit at gcc dot gnu.org
@ 2021-08-10 16:07 ` cvs-commit at gcc dot gnu.org
  2021-08-10 16:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-10 16:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:0e54986854831a4c66b308f98aff949ca7d3ce84

commit r10-10026-g0e54986854831a4c66b308f98aff949ca7d3ce84
Author: Jonathan Wakely <jwakely@redhat.com>
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 <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/100894
            * include/std/type_traits (__common_ref_impl<X&, Y&>): Only
            use the type if it's a reference.
            * testsuite/20_util/common_reference/100894.cc: New test.

    (cherry picked from commit c37b5ddcc88e0cc0f6a4ad609eda51021df0f6bb)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100894] The std::common_reference implementation seems to be wrong
  2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2021-08-10 16:07 ` cvs-commit at gcc dot gnu.org
@ 2021-08-10 16:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-10 16:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 10.4 and 11.2, thanks

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-10 16:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 16:35 [Bug libstdc++/100894] New: The std::common_reference implementation seems to be wrong hewillk at gmail dot com
2021-06-14 17:25 ` [Bug libstdc++/100894] " redi at gcc dot gnu.org
2021-06-14 19:30 ` redi at gcc dot gnu.org
2021-06-14 20:17 ` cvs-commit at gcc dot gnu.org
2021-06-14 21:49 ` cvs-commit at gcc dot gnu.org
2021-08-10 16:07 ` cvs-commit at gcc dot gnu.org
2021-08-10 16:07 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).