mercredi 26 avril 2017

error: reinterpret_cast from integer to pointer

The following code fails to compile with GCC 6 and 32bit-mode (on a amd64 host).

class foo {
  static constexpr const char* ptr = reinterpret_cast<const char*>(0xff);
};

int main() {
  return 0;
}

Compilation command:

g++ -m32 test.cc

Error message is:

test.cc:2:38: error: reinterpret_cast from integer to pointer
   static constexpr const char* ptr = reinterpret_cast<const char*>(0xff);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It works with older compilers (GCC 4.9). It also works as inline definition (not as static member variable) or compiled in 64 bit mode.

Is there a way to get it working with GCC 6?

Aucun commentaire:

Enregistrer un commentaire