Web lists-archives.com

Re: cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast




Hi Paolo,

On Mon, Oct 23, 2017 at 4:47 PM, Paolo ZAMBOTTI <paolo.zambotti@xxxxxx> wrote:
> Hello,
>
> I'm having some issues while compiling C++ code with mingw64 c++ compiler (6.4.0) distributed within Cygwin packages.
> I can guess the issue I'm going to report is not strictly related to Cygwin distribution but I cannot test other mingw64 distributions so let me start reporting the issue here...
> Once said that, I'm open to any suggestions for better reporting place...
>
> I'm not an expert in C and even less in C++ so I hope to not generate stupid noise... but the same code was compiling fine with previous version (5.4) ...

Note that compilers tend to become more picky with time. The fact that
this code was compiling fine with GCC 5.4 may well be a bug in GCC 5.4

$ gcc-630 -std=gnu++11 -c -Wall -pedantic -Wextra fail.cpp
fail.cpp: In function ‘int main(int, char**)’:
fail.cpp:10:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test1 = (void*)(-1LL);
                                  ^~~~~~~~~~~~~
fail.cpp:11:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test2 = (void*)(-1L);
                                  ^~~~~~~~~~~~

$ gcc-7 -std=gnu++11 -c -Wall -pedantic -Wextra fail.cpp
gcc-7    gcc-710
csabaraduly@HU-GD-36813:/tmp
$ gcc-7 -std=gnu++11 -c -Wall -pedantic -Wextra fail.cpp
fail.cpp: In function ‘int main(int, char**)’:
fail.cpp:10:34: error: ‘reinterpret_cast<void*>(-1)’ is not a constant
expression
   static constexpr void* test1 = (void*)(-1LL);
                                  ^~~~~~~~~~~~~
fail.cpp:11:34: error: ‘reinterpret_cast<void*>(-1)’ is not a constant
expression
   static constexpr void* test2 = (void*)(-1L);
                                  ^~~~~~~~~~~~

$ gcc-8 -std=gnu++11 -c -Wall -pedantic -Wextra fail.cpp
fail.cpp: In function ‘int main(int, char**)’:
fail.cpp:10:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test1 = (void*)(-1LL);
                                  ^~~~~~~~~~~~~
fail.cpp:11:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test2 = (void*)(-1L);
                                  ^~~~~~~~~~~~

$ clang++ -std=gnu++11 -c -Wall -pedantic -Wextra fail.cpp
fail.cpp:10:26: error: constexpr variable 'test1' must be initialized
by a constant expression
  static constexpr void* test1 = (void*)(-1LL);
                         ^       ~~~~~~~~~~~~~
fail.cpp:10:34: note: cast that performs the conversions of a
reinterpret_cast is not allowed in a constant expression
  static constexpr void* test1 = (void*)(-1LL);
                                 ^
fail.cpp:11:26: error: constexpr variable 'test2' must be initialized
by a constant expression
  static constexpr void* test2 = (void*)(-1L);
                         ^       ~~~~~~~~~~~~
fail.cpp:11:34: note: cast that performs the conversions of a
reinterpret_cast is not allowed in a constant expression
  static constexpr void* test2 = (void*)(-1L);
                                 ^

I think clang explains it best.
Note: these were Linux compilers, but your question is not
Cygwin-specific (and including windows.h is unnecessary).

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple