https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63391

            Bug ID: 63391
           Summary: Erroneous -Wsign-conversion with offsetof
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at geometrian dot com

//Bug report:
//    by Ian Mallett
//    Compile with "g++ <name.cpp> -std=c++11 -Wsign-conversion

#include <cstdint>
#include <cstddef>


struct Foo {
    char data;
};


int main(int /*argc*/, char* /*argv*/[]) {
    int num = 6;
    #if 0 //No warning
        size_t offset = offsetof(struct Foo,data);
        delete [] new char[offset*static_cast<size_t>(num)];
    #else //warning
        delete [] new char[offsetof(struct Foo,data)*static_cast<size_t>(num)];
    #endif

    return 0;
}

Reply via email to