public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1)
@ 2020-12-24 21:38 aschepler at gmail dot com
  2020-12-27 20:16 ` [Bug c++/98440] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: aschepler at gmail dot com @ 2020-12-24 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98440
           Summary: Accepts ill-formed reinterpret_cast<int&&>(1)
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aschepler at gmail dot com
  Target Milestone: ---

g++ does not give any error or warning for a reinterpret_cast when the target
type is an rvalue reference type and the expression operand is a prvalue, for
example reinterpret_cast<int&&>(1).

In standard section [expr.reinterpret.cast], casts to reference types are
described only by paragraph 11, which allows casting a glvalue to a reference
type, but specifically says "No temporary is created". So the temporary
materialization conversion can't be implicitly used like in most expressions,
and the paragraph can't apply.

Clang++, MSVC, and ICC all produce error messages for the expression
reinterpret_cast<int&&>(1).

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

* [Bug c++/98440] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
@ 2020-12-27 20:16 ` redi at gcc dot gnu.org
  2020-12-27 20:19 ` [Bug c++/98440] [9/10/11 Regression] " redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-27 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-12-27
             Status|UNCONFIRMED                 |NEW

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

* [Bug c++/98440] [9/10/11 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
  2020-12-27 20:16 ` [Bug c++/98440] " redi at gcc dot gnu.org
@ 2020-12-27 20:19 ` redi at gcc dot gnu.org
  2021-01-14 11:14 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-27 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.1.0, 11.0, 9.2.0
   Target Milestone|---                         |9.4
            Summary|Accepts ill-formed          |[9/10/11 Regression]
                   |reinterpret_cast<int&&>(1)  |Accepts ill-formed
                   |                            |reinterpret_cast<int&&>(1)
                 CC|                            |jason at gcc dot gnu.org
      Known to work|                            |8.3.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This was correctly rejected until r260622:

    Fix cast to rvalue reference from prvalue.

            * cvt.c (diagnose_ref_binding): Handle rvalue reference.
            * rtti.c (build_dynamic_cast_1): Don't try to build a reference to
            non-class type.  Handle xvalue argument.
            * typeck.c (build_reinterpret_cast_1): Allow cast from prvalue to
            rvalue reference.
            * semantics.c (finish_compound_literal): Do direct-initialization,
            not cast, to initialize a reference.

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

* [Bug c++/98440] [9/10/11 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
  2020-12-27 20:16 ` [Bug c++/98440] " redi at gcc dot gnu.org
  2020-12-27 20:19 ` [Bug c++/98440] [9/10/11 Regression] " redi at gcc dot gnu.org
@ 2021-01-14 11:14 ` rguenth at gcc dot gnu.org
  2021-04-05 19:46 ` jason at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-14 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/98440] [9/10/11 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (2 preceding siblings ...)
  2021-01-14 11:14 ` rguenth at gcc dot gnu.org
@ 2021-04-05 19:46 ` jason at gcc dot gnu.org
  2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2021-04-05 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

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

* [Bug c++/98440] [9/10/11 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-05 19:46 ` jason at gcc dot gnu.org
@ 2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
  2021-04-05 21:30 ` [Bug c++/98440] [9/10 " jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-05 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:07f56824fd4da14a48030e698c8eb58de951c741

commit r11-7994-g07f56824fd4da14a48030e698c8eb58de951c741
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 5 15:50:48 2021 -0400

    c++: reinterpret_cast from prvalue to rvalue ref [PR98440]

    In r260622 I allowed this under the general principle that [basic.lval]
    "Whenever a prvalue appears as an operand of an operator that expects a
    glvalue for that operand, the temporary materialization conversion (7.3.4)
    is applied to convert the expression to an xvalue."  But
    [expr.reinterpret.cast] specifically excludes creating a temporary in this
    case.

    gcc/cp/ChangeLog:

            PR c++/98440
            * typeck.c (build_reinterpret_cast_1): Don't perform
            temporary materialization.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/rv-cast6.C: Expect reinterpret_cast error.
            * g++.dg/cpp0x/reinterpret_cast2.C: Adjust message.
            * g++.old-deja/g++.jason/rvalue3.C: Likewise.

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

* [Bug c++/98440] [9/10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (4 preceding siblings ...)
  2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
@ 2021-04-05 21:30 ` jason at gcc dot gnu.org
  2021-06-01  8:19 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2021-04-05 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[9/10/11 Regression]        |[9/10 Regression] Accepts
                   |Accepts ill-formed          |ill-formed
                   |reinterpret_cast<int&&>(1)  |reinterpret_cast<int&&>(1)
      Known to fail|11.0                        |
      Known to work|                            |11.0

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11 so far.

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

* [Bug c++/98440] [9/10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (5 preceding siblings ...)
  2021-04-05 21:30 ` [Bug c++/98440] [9/10 " jason at gcc dot gnu.org
@ 2021-06-01  8:19 ` rguenth at gcc dot gnu.org
  2021-07-27 22:22 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01  8:19 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.4                         |9.5

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.

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

* [Bug c++/98440] [9/10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (6 preceding siblings ...)
  2021-06-01  8:19 ` rguenth at gcc dot gnu.org
@ 2021-07-27 22:22 ` pinskia at gcc dot gnu.org
  2022-05-27  9:44 ` [Bug c++/98440] [10 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 22:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zhonghao at pku dot org.cn

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 86633 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98440] [10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (7 preceding siblings ...)
  2021-07-27 22:22 ` pinskia at gcc dot gnu.org
@ 2022-05-27  9:44 ` rguenth at gcc dot gnu.org
  2022-06-28 10:42 ` jakub at gcc dot gnu.org
  2023-07-07  9:20 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:44 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

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

* [Bug c++/98440] [10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (8 preceding siblings ...)
  2022-05-27  9:44 ` [Bug c++/98440] [10 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:42 ` jakub at gcc dot gnu.org
  2023-07-07  9:20 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:42 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

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

* [Bug c++/98440] [10 Regression] Accepts ill-formed reinterpret_cast<int&&>(1)
  2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
                   ` (9 preceding siblings ...)
  2022-06-28 10:42 ` jakub at gcc dot gnu.org
@ 2023-07-07  9:20 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|10.5                        |11.0
      Known to fail|                            |10.5.0

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in GCC 11.

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

end of thread, other threads:[~2023-07-07  9:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24 21:38 [Bug c++/98440] New: Accepts ill-formed reinterpret_cast<int&&>(1) aschepler at gmail dot com
2020-12-27 20:16 ` [Bug c++/98440] " redi at gcc dot gnu.org
2020-12-27 20:19 ` [Bug c++/98440] [9/10/11 Regression] " redi at gcc dot gnu.org
2021-01-14 11:14 ` rguenth at gcc dot gnu.org
2021-04-05 19:46 ` jason at gcc dot gnu.org
2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
2021-04-05 21:30 ` [Bug c++/98440] [9/10 " jason at gcc dot gnu.org
2021-06-01  8:19 ` rguenth at gcc dot gnu.org
2021-07-27 22:22 ` pinskia at gcc dot gnu.org
2022-05-27  9:44 ` [Bug c++/98440] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07  9:20 ` rguenth 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).