public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54580] New: 64-bit pointer to int cast fails
@ 2012-09-14 16:23 russell.wallace at gmail dot com
  2012-09-14 17:08 ` [Bug c++/54580] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: russell.wallace at gmail dot com @ 2012-09-14 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54580
           Summary: 64-bit pointer to int cast fails
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: russell.wallace@gmail.com


int main() { return (int)""; }

a.cc: In function 'int main()':
a.cc:1:26: error: cast from 'const char*' to 'int' loses precision
[-fpermissive]

This should not be a warning let alone an error, because an explicit cast was
used (though it would do no harm to retain it as a warning under -Wextra if so
desired).

Note that the -fpermissive workaround suggested in the message won't be a
solution in all cases because this is going to trigger on code that was
originally written - along with its build scripts - on 32-bit systems; in many
cases the author of the code will no longer be available to fix the problem.

Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++
COLLECT_LTO_WRAPPER=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32
--prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root
--with-sysroot=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root
--enable-languages=all,obj-c++ --enable-fully-dynamic-string --disable-multilib
Thread model: win32
gcc version 4.7.0 20111220 (experimental) (GCC)


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

* [Bug c++/54580] 64-bit pointer to int cast fails
  2012-09-14 16:23 [Bug c++/54580] New: 64-bit pointer to int cast fails russell.wallace at gmail dot com
@ 2012-09-14 17:08 ` pinskia at gcc dot gnu.org
  2012-09-15 17:53 ` redi at gcc dot gnu.org
  2012-09-15 17:58 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-09-14 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-09-14 17:07:50 UTC ---
C++ is not C.


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

* [Bug c++/54580] 64-bit pointer to int cast fails
  2012-09-14 16:23 [Bug c++/54580] New: 64-bit pointer to int cast fails russell.wallace at gmail dot com
  2012-09-14 17:08 ` [Bug c++/54580] " pinskia at gcc dot gnu.org
@ 2012-09-15 17:53 ` redi at gcc dot gnu.org
  2012-09-15 17:58 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-15 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

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> 2012-09-15 17:52:43 UTC ---
That explicit type conversion (i.e. cast) is equivalent to
reinterpret_cast<int>("") and the standard says reinterpret_cast can be used to
convert a pointer to an integer type large enough to hold it. The code is
invalid and should be rejected by any 64-bit C++ compiler, just as (short)""
should be by 32-bit compilers.


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

* [Bug c++/54580] 64-bit pointer to int cast fails
  2012-09-14 16:23 [Bug c++/54580] New: 64-bit pointer to int cast fails russell.wallace at gmail dot com
  2012-09-14 17:08 ` [Bug c++/54580] " pinskia at gcc dot gnu.org
  2012-09-15 17:53 ` redi at gcc dot gnu.org
@ 2012-09-15 17:58 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-15 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-09-15 17:57:52 UTC ---
Or strictly, should be rejected by any 64-bit compiler with 32-bit int (which
is practically all of them) and any 32-bit compiler with 16-bit short.
Certainly invalid for g++ on LP64 platforms.


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

end of thread, other threads:[~2012-09-15 17:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-14 16:23 [Bug c++/54580] New: 64-bit pointer to int cast fails russell.wallace at gmail dot com
2012-09-14 17:08 ` [Bug c++/54580] " pinskia at gcc dot gnu.org
2012-09-15 17:53 ` redi at gcc dot gnu.org
2012-09-15 17:58 ` 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).