public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast
@ 2022-09-29 10:30 roi.jacobson1 at gmail dot com
  2022-09-29 10:42 ` [Bug c++/107085] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: roi.jacobson1 at gmail dot com @ 2022-09-29 10:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107085
           Summary: __reference_constructs_from_temporary does not detect
                    static up-cast
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roi.jacobson1 at gmail dot com
  Target Milestone: ---

This example:

struct Base {};
struct Derived : Base {};
static_assert(__reference_constructs_from_temporary(Base&, Derived));

fails to compile, but according to p2255r1 it seems correct to me.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
@ 2022-09-29 10:42 ` redi at gcc dot gnu.org
  2022-09-29 10:46 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-29 10:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
You can't bind a non-const Base& to a Derived prvalue, so this seems correct.
The reference doesn't bind to it at all, so it doesn't bind to a temporary.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
  2022-09-29 10:42 ` [Bug c++/107085] " redi at gcc dot gnu.org
@ 2022-09-29 10:46 ` redi at gcc dot gnu.org
  2022-09-29 11:11 ` roi.jacobson1 at gmail dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-29 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
#include <type_traits>
using namespace std;
struct Base {};
struct Derived : Base {};
static_assert( conjunction_v<is_reference<Base&>, is_constructible<Base&,
Derived>> );

This fails (as expected) and so the reference_constructs_from_temporary is
required to be false.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
  2022-09-29 10:42 ` [Bug c++/107085] " redi at gcc dot gnu.org
  2022-09-29 10:46 ` redi at gcc dot gnu.org
@ 2022-09-29 11:11 ` roi.jacobson1 at gmail dot com
  2022-09-29 11:52 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: roi.jacobson1 at gmail dot com @ 2022-09-29 11:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Roy Jacobson <roi.jacobson1 at gmail dot com> ---
Thanks! But a Base const& is still not detected:

static_assert(__reference_constructs_from_temporary(Base const&, Derived));

And in this case I think it _is_ a bug that this doesn't compile?

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-09-29 11:11 ` roi.jacobson1 at gmail dot com
@ 2022-09-29 11:52 ` redi at gcc dot gnu.org
  2022-09-29 12:45 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-29 11:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
     Ever confirmed|0                           |1
           Keywords|                            |wrong-code
            Version|unknown                     |13.0
   Last reconfirmed|                            |2022-09-29
         Resolution|INVALID                     |---
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, I think that's a bug.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-09-29 11:52 ` redi at gcc dot gnu.org
@ 2022-09-29 12:45 ` mpolacek at gcc dot gnu.org
  2022-10-04 19:34 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-09-29 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Mine then.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (4 preceding siblings ...)
  2022-09-29 12:45 ` mpolacek at gcc dot gnu.org
@ 2022-10-04 19:34 ` mpolacek at gcc dot gnu.org
  2022-10-04 20:41 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-04 19:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Roy Jacobson from comment #3)
> Thanks! But a Base const& is still not detected:
> 
> static_assert(__reference_constructs_from_temporary(Base const&, Derived));
> 
> And in this case I think it _is_ a bug that this doesn't compile?

To make sure I understand this correctly, __reference_constructs_from_temporary
should say "yes" here, because it's just like

  const Base& b(Derived{});

where we bind 'b' to the Base subobject of a temporary Derived object, yes?

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (5 preceding siblings ...)
  2022-10-04 19:34 ` mpolacek at gcc dot gnu.org
@ 2022-10-04 20:41 ` mpolacek at gcc dot gnu.org
  2022-10-05  6:43 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-04 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
...which could be fixed with

--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -9186,7 +9186,9 @@ conv_is_prvalue (conversion *c)
 {
   if (c->kind == ck_rvalue)
     return true;
-  if (c->kind == ck_base && c->need_temporary_p)
+  if (c->kind == ck_base
+      /* TODO */
+      && (c->need_temporary_p || conv_is_prvalue (next_conversion (c))))
     return true;
   if (c->kind == ck_user && !TYPE_REF_P (c->type))
     return true;

but that then causes ICEs in build_over_call, at cp/call.cc:9987

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (6 preceding siblings ...)
  2022-10-04 20:41 ` mpolacek at gcc dot gnu.org
@ 2022-10-05  6:43 ` redi at gcc dot gnu.org
  2022-10-05 15:29 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-10-05  6:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #6)
> where we bind 'b' to the Base subobject of a temporary Derived object, yes?

Yes, exactly right.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (7 preceding siblings ...)
  2022-10-05  6:43 ` redi at gcc dot gnu.org
@ 2022-10-05 15:29 ` mpolacek at gcc dot gnu.org
  2022-10-05 16:07 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-05 15:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
A distilled test that ICEs with the patch:

struct X {
  virtual void f();
};
struct Z : X {};
constexpr auto x = sizeof((X(Z())));


s.C:5:33: internal compiler error: in build_over_call, at cp/call.cc:9987
    5 | constexpr auto x = sizeof((X(Z())));
      |                                 ^
0xb54c2a build_over_call
        /home/mpolacek/src/gcc/gcc/cp/call.cc:9987

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (8 preceding siblings ...)
  2022-10-05 15:29 ` mpolacek at gcc dot gnu.org
@ 2022-10-05 16:07 ` mpolacek at gcc dot gnu.org
  2022-10-07 22:06 ` cvs-commit at gcc dot gnu.org
  2022-10-07 22:06 ` mpolacek at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-05 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Even more simplified:

struct X {
  virtual void f();
};
struct Z : X {};
constexpr X x = X(Z());

I guess we shouldn't try to force_elide X::X(X&&) here because X is a
potentially-overlapping subobject.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (9 preceding siblings ...)
  2022-10-05 16:07 ` mpolacek at gcc dot gnu.org
@ 2022-10-07 22:06 ` cvs-commit at gcc dot gnu.org
  2022-10-07 22:06 ` mpolacek at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-07 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:895dd027d5dda51a95d242aec8a49a6dfa5db58d

commit r13-3173-g895dd027d5dda51a95d242aec8a49a6dfa5db58d
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Oct 5 15:51:30 2022 -0400

    c++: fixes for derived-to-base reference binding [PR107085]

    This PR reports that

      struct Base {};
      struct Derived : Base {};
      static_assert(__reference_constructs_from_temporary(Base const&,
Derived));

    doesn't pass, which it should: it's just like

      const Base& b(Derived{});

    where we bind 'b' to the Base subobject of a temporary object of type
    Derived.  The ck_base conversion didn't have ->need_temporary_p set because
    we didn't need to create a temporary object just for the base, but the
whole
    object is a temporary so we're still binding to a temporary.  Since the
    Base subobject is an xvalue, a new function is introduced.

            PR c++/107085

    gcc/cp/ChangeLog:

            * call.cc (conv_binds_ref_to_temporary): New.
            (ref_conv_binds_directly): Rename to...
            (ref_conv_binds_to_temporary): ...this.  Use
            conv_binds_ref_to_temporary.
            * cp-tree.h (ref_conv_binds_directly): Rename to...
            (ref_conv_binds_to_temporary): ...this.
            * method.cc (ref_xes_from_temporary): Use
ref_conv_binds_to_temporary.
            * parser.cc (warn_for_range_copy): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/reference_constructs_from_temporary1.C: Adjust
expected
            result.
            * g++.dg/ext/reference_converts_from_temporary1.C: Likewise.
            * g++.dg/cpp0x/elision4.C: New test.

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

* [Bug c++/107085] __reference_constructs_from_temporary does not detect static up-cast
  2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
                   ` (10 preceding siblings ...)
  2022-10-07 22:06 ` cvs-commit at gcc dot gnu.org
@ 2022-10-07 22:06 ` mpolacek at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-07 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-10-07 22:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 10:30 [Bug c++/107085] New: __reference_constructs_from_temporary does not detect static up-cast roi.jacobson1 at gmail dot com
2022-09-29 10:42 ` [Bug c++/107085] " redi at gcc dot gnu.org
2022-09-29 10:46 ` redi at gcc dot gnu.org
2022-09-29 11:11 ` roi.jacobson1 at gmail dot com
2022-09-29 11:52 ` redi at gcc dot gnu.org
2022-09-29 12:45 ` mpolacek at gcc dot gnu.org
2022-10-04 19:34 ` mpolacek at gcc dot gnu.org
2022-10-04 20:41 ` mpolacek at gcc dot gnu.org
2022-10-05  6:43 ` redi at gcc dot gnu.org
2022-10-05 15:29 ` mpolacek at gcc dot gnu.org
2022-10-05 16:07 ` mpolacek at gcc dot gnu.org
2022-10-07 22:06 ` cvs-commit at gcc dot gnu.org
2022-10-07 22:06 ` mpolacek 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).