public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36607]  New: Incorrect type diagnostic on substracting casted char pointers
@ 2008-06-23 16:09 rschiele at gmail dot com
  2008-12-28  0:42 ` [Bug c++/36607] " pinskia at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 16+ messages in thread
From: rschiele at gmail dot com @ 2008-06-23 16:09 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1483 bytes --]

The following little code sample does no longer compile with 4.3 or higher:

struct a {};
void b() {
    int a::*m;
    a *c;
    int p = reinterpret_cast<char*>(&(c->*m)) - reinterpret_cast<char*>(c);
}

Instead the compiler emits the error message:

bad.cc: In function ‘void b()’:
bad.cc:5: error: aggregate value used where an integer was expected

Though it is clear that this code sample is not perfectly valid according to
the C++ standard since "reinterpret_cast<char*>(&(c->*m))" and
"reinterpret_cast<char*>(c)" are not part of the same array I would not expect
this kind of behavior since the claim of the compiler that there is something
wrong with types is completely bogus.

Rewriting the code like the following makes the compiler accepting it again:

struct a {};
void b() {
    int a::*m;
    a *c;
    char* d = reinterpret_cast<char*>(&(c->*m));
    char* e = reinterpret_cast<char*>(c);
    int p = d - e;
}


-- 
           Summary: Incorrect type diagnostic on substracting casted char
                    pointers
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rschiele at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

end of thread, other threads:[~2009-06-19 21:46 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-23 16:09 [Bug c++/36607] New: Incorrect type diagnostic on substracting casted char pointers rschiele at gmail dot com
2008-12-28  0:42 ` [Bug c++/36607] " pinskia at gcc dot gnu dot org
2008-12-30  6:10 ` rschiele at gmail dot com
2008-12-30  6:17 ` [Bug c++/36607] [4.3/4.4 Regression] " pinskia at gcc dot gnu dot org
2008-12-30 17:14 ` pinskia at gcc dot gnu dot org
2009-01-03 15:29 ` rguenth at gcc dot gnu dot org
2009-01-24 10:25 ` rguenth at gcc dot gnu dot org
2009-02-03 13:56 ` bonzini at gnu dot org
2009-02-03 15:44   ` Andrew Thomas Pinski
2009-02-03 15:44 ` pinskia at gmail dot com
2009-02-03 22:38 ` pinskia at gcc dot gnu dot org
2009-02-03 22:39 ` [Bug c++/36607] [4.3 " pinskia at gcc dot gnu dot org
2009-04-16 15:44 ` pinskia at gcc dot gnu dot org
2009-06-19 16:51 ` rguenth at gcc dot gnu dot org
2009-06-19 21:45 ` rguenth at gcc dot gnu dot org
2009-06-19 21:46 ` rguenth at gcc dot gnu dot 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).