This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]