[Bug c++/36607] New: Incorrect type diagnostic on substracting casted char pointers

rschiele at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 23 16:09:00 GMT 2008


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



More information about the Gcc-bugs mailing list