public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51379] New: reinterpret_cast is not particularly useful
@ 2011-12-01 12:57 piotr.wyderski at gmail dot com
  2011-12-01 12:58 ` [Bug c++/51379] " piotr.wyderski at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: piotr.wyderski at gmail dot com @ 2011-12-01 12:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

             Bug #: 51379
           Summary: reinterpret_cast is not particularly useful
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: piotr.wyderski@gmail.com


The following code:

int main() {

    unsigned long t1 = 0;
    unsigned long t2 = 1;
    t1 = reinterpret_cast<unsigned long>(t2);
    return 0;
}

compiled using GCC 4.6.2 on Linux/x64:

g++ test.cpp

fails displaying:

test.cpp:5:44: error: invalid cast from type 'long unsigned int' to type 'long
unsigned int'

IMHO this is a rather urgent issue.


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

* [Bug c++/51379] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
@ 2011-12-01 12:58 ` piotr.wyderski at gmail dot com
  2011-12-01 13:20 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: piotr.wyderski at gmail dot com @ 2011-12-01 12:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

--- Comment #1 from Piotr Wyderski <piotr.wyderski at gmail dot com> 2011-12-01 12:58:16 UTC ---
Both static_cast and C-type cast work as expected.


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

* [Bug c++/51379] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
  2011-12-01 12:58 ` [Bug c++/51379] " piotr.wyderski at gmail dot com
@ 2011-12-01 13:20 ` redi at gcc dot gnu.org
  2011-12-01 13:59 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-01 13:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

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

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-01 13:20:16 UTC ---
This is required by the standard.

[expr.reinterpret.cast] explicitly lists all the conversion allowed by
reinterpret_cast

You'll get the same result from http://llvm.org/demo/ and
http://www.comeaucomputing.com/tryitout/

If GCC, EDG and Clang all reject your code then your code is probably wrong.


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

* [Bug c++/51379] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
  2011-12-01 12:58 ` [Bug c++/51379] " piotr.wyderski at gmail dot com
  2011-12-01 13:20 ` redi at gcc dot gnu.org
@ 2011-12-01 13:59 ` jakub at gcc dot gnu.org
  2011-12-01 14:07 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-12-01 13:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-12-01 13:58:29 UTC ---
I wonder about the C++11 wording though, in C++03 it said:
"The reinterpret_cast operator shall not cast away constness. [Note: see 5.2.11
for the definition of ‘‘casting away constness’’. Subject to the restrictions
in this section, an expression may be cast to its own type using a
reinterpret_cast operator. ]"
but in C++11:
"The reinterpret_cast operator shall not cast away constness (5.2.11). An
expression of integral, enumeration, pointer, or pointer-to-member type can be
explicitly converted to its own type; such a cast yields the
value of its operand."
For the latter wording it isn't obvious if the second sentence is subject to
the other restrictions or not.


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

* [Bug c++/51379] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
                   ` (2 preceding siblings ...)
  2011-12-01 13:59 ` jakub at gcc dot gnu.org
@ 2011-12-01 14:07 ` redi at gcc dot gnu.org
  2011-12-31 21:54 ` [Bug c++/51379] [C++0x] [DR 799] " paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-01 14:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2011-12-01
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-01 14:06:47 UTC ---
Ah good point, I didn't realise DR 799 changed that
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#799


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

* [Bug c++/51379] [C++0x] [DR 799] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
                   ` (3 preceding siblings ...)
  2011-12-01 14:07 ` redi at gcc dot gnu.org
@ 2011-12-31 21:54 ` paolo.carlini at oracle dot com
  2012-01-01 20:22 ` paolo at gcc dot gnu.org
  2012-01-01 20:24 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-12-31 21:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |paolo.carlini at oracle dot
                   |gnu.org                     |com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-12-31 17:58:09 UTC ---
On it.


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

* [Bug c++/51379] [C++0x] [DR 799] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
                   ` (4 preceding siblings ...)
  2011-12-31 21:54 ` [Bug c++/51379] [C++0x] [DR 799] " paolo.carlini at oracle dot com
@ 2012-01-01 20:22 ` paolo at gcc dot gnu.org
  2012-01-01 20:24 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-01-01 20:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-01-01 20:21:39 UTC ---
Author: paolo
Date: Sun Jan  1 20:21:36 2012
New Revision: 182775

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182775
Log:
/cp
2012-01-01  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51379
    * typeck.c (build_reinterpret_cast_1): Implement resolution of
    DR 799.

/testsuite
2012-01-01  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51379
    * g++.dg/conversion/reinterpret4.C: New.
    * g++.dg/conversion/reinterpret1.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/conversion/reinterpret4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/conversion/reinterpret1.C


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

* [Bug c++/51379] [C++0x] [DR 799] reinterpret_cast is not particularly useful
  2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
                   ` (5 preceding siblings ...)
  2012-01-01 20:22 ` paolo at gcc dot gnu.org
@ 2012-01-01 20:24 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-01 20:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51379

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-01 20:23:50 UTC ---
Done.


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

end of thread, other threads:[~2012-01-01 20:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-01 12:57 [Bug c++/51379] New: reinterpret_cast is not particularly useful piotr.wyderski at gmail dot com
2011-12-01 12:58 ` [Bug c++/51379] " piotr.wyderski at gmail dot com
2011-12-01 13:20 ` redi at gcc dot gnu.org
2011-12-01 13:59 ` jakub at gcc dot gnu.org
2011-12-01 14:07 ` redi at gcc dot gnu.org
2011-12-31 21:54 ` [Bug c++/51379] [C++0x] [DR 799] " paolo.carlini at oracle dot com
2012-01-01 20:22 ` paolo at gcc dot gnu.org
2012-01-01 20:24 ` paolo.carlini at oracle dot com

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).