public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast
@ 2017-10-31 10:01 Paolo ZAMBOTTI
  2017-11-01 14:25 ` Csaba Raduly
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo ZAMBOTTI @ 2017-10-31 10:01 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 5198 bytes --]

Hi Csaba,

Ok, then the issue are "my" lines of code and the error messages from g++ were not completely clear (and they was confusing me a little bit)...
But I'm still not sure the issue is not in Cygwin package. I mean, my test code was a very simplified (too much simplified) excerpt from squid source code and, there, the link with header file from cygwin package is more clear.
Then, let me post another test file where this link is more clear.

Now the failure is as follow (g++ -std=gnu++11 -c -Wall -pedantic -Wextra test.cpp)

In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/winbase.h:19:0,
                 from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:70,
                 from test.cpp:1:
test.cpp:6:45: error: reinterpret_cast from integer to pointer
     static constexpr HANDLE InvalidHandle = INVALID_HANDLE_VALUE;
                                             ^

The issue is now within the macro definition of INVALID_HANDLE_VALUE in file handleapi.h (which could be, from i686-w64-mingw32, x86_64-w64-mingw32 or w32api)

Now I'm wondering what is really wrong:
	does the definition of INVALID_HANDLE_VALUE need to be rewritten in order to be compatible with the "static constexpr" line
	or
	does "my" line of code has to be rewritten in order to be compatible with the INVALID_HANDLE_VALUE definition?

In the latest case, any suggestion will be very welcome...

Paolo.

> Hi Paolo,
> 
> On Mon, Oct 23, 2017 at 4:47 PM, Paolo ZAMBOTTI <paolo.zambotti@st.com> 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

[-- Attachment #2: test.cpp --]
[-- Type: text/plain, Size: 389 bytes --]

#include <windows.h>
#include <stdio.h>

class test {
  private:
    static constexpr HANDLE InvalidHandle = INVALID_HANDLE_VALUE;
    
  public:
    HANDLE get_InvHahndle(void) {
      return InvalidHandle;
    }
};
  

int main (__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
  test fail;
  
  printf("%llx\n", (long long)(fail.get_InvHahndle()));

return 0;

}

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast
  2017-10-31 10:01 cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast Paolo ZAMBOTTI
@ 2017-11-01 14:25 ` Csaba Raduly
  0 siblings, 0 replies; 5+ messages in thread
From: Csaba Raduly @ 2017-11-01 14:25 UTC (permalink / raw)
  To: cygwin list

On Tue, Oct 31, 2017 at 11:00 AM, Paolo ZAMBOTTI  wrote:
> Hi Csaba,
>

Please don't top-post (at least in this mailing list).

> Ok, then the issue are "my" lines of code and the error messages from g++ were not completely clear (and they was confusing me a little bit)...
> But I'm still not sure the issue is not in Cygwin package. I mean, my test code was a very simplified (too much simplified) excerpt from squid source code and, there, the link with header file from cygwin package is more clear.
> Then, let me post another test file where this link is more clear.
>
> Now the failure is as follow (g++ -std=gnu++11 -c -Wall -pedantic -Wextra test.cpp)
>
> In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/winbase.h:19:0,
>                  from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:70,
>                  from test.cpp:1:
> test.cpp:6:45: error: reinterpret_cast from integer to pointer
>      static constexpr HANDLE InvalidHandle = INVALID_HANDLE_VALUE;
>                                              ^
>
> The issue is now within the macro definition of INVALID_HANDLE_VALUE in file handleapi.h (which could be, from i686-w64-mingw32, x86_64-w64-mingw32 or w32api)
>
> Now I'm wondering what is really wrong:
>         does the definition of INVALID_HANDLE_VALUE need to be rewritten in order to be compatible with the "static constexpr" line

There's nothing wrong with INVALID_HANDLE_VALUE with regards to
"static constexpr", although a constexpr expression cannot contain
reinterpret_cast-s,
and a C-style cast can resort to be a reinterpret_cast. But this
doesn't seem to be the problem (there's a different error message for
that).

HANDLE is defined as a pointer:

include/wtypesbase.h:52:typedef void *HANDLE;

LONG_PTR is defined as an integer:
basetsd.h:54:typedef long LONG_PTR,*PLONG_PTR;

INVALID_HANDLE_VALUE is defined in handleapi.h:16 as

#define INVALID_HANDLE_VALUE ((HANDLE) (LONG_PTR)-1)

so you have a cast right there. Whenever you use INVALID_HANDLE_VALUE,
the compiler sees a cast from long to void*

I don't know how this could be fixed. You may want to ask on a
mingw-specific mailing list.

You could try adding -isystem /path/to/mingw/headers so mingw-gcc
finds its headers that way (warnings tend to be suppressed for headers
found in directories specified with -isystem rather than -i, although
mingw-gcc's built-in headers should be treated the same way).

(disclaimer: I havent tried this).

>         or
>         does "my" line of code has to be rewritten in order to be compatible with the INVALID_HANDLE_VALUE definition?
>
> In the latest case, any suggestion will be very welcome...
>
> Paolo.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast
  2017-10-23 14:47 Paolo ZAMBOTTI
  2017-10-23 23:26 ` JonY
@ 2017-10-24  9:19 ` Csaba Raduly
  1 sibling, 0 replies; 5+ messages in thread
From: Csaba Raduly @ 2017-10-24  9:19 UTC (permalink / raw)
  To: cygwin list

Hi Paolo,

On Mon, Oct 23, 2017 at 4:47 PM, Paolo ZAMBOTTI <paolo.zambotti@st.com> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast
  2017-10-23 14:47 Paolo ZAMBOTTI
@ 2017-10-23 23:26 ` JonY
  2017-10-24  9:19 ` Csaba Raduly
  1 sibling, 0 replies; 5+ messages in thread
From: JonY @ 2017-10-23 23:26 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 1808 bytes --]

On 10/23/2017 02:47 PM, Paolo ZAMBOTTI 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) ...
> 

Neither am I.

> The attached file is the simplest example that triggers the issue.
> 
> If I try to compile with "x86_64-w64-mingw32-gcc -o test.exe test.cpp" the output is the following
> 
> test.cpp: In function 'int main(int, char**)':
> test.cpp:7:34: error: reinterpret_cast from integer to pointer
>    static constexpr void* test2 = (void*)(-1LL);
>                                   ^~~~~~~~~~~~~
> 
> While, if I try to compile with "i686-w64-mingw32-gcc -o test.exe test.cpp" the output is the following
> 
> test.cpp: In function 'int main(int, char**)':
> test.cpp:12:34: error: reinterpret_cast from integer to pointer
>    static constexpr void* test2 = (void*)(-1L);
>                                   ^~~~~~~~~~~~
> 

As a comparison, both -1L and -1LL fails for me on 64bit Linux with
gcc-6.4.0.

> The test is effectively build to always fail but the current behavior is exactly the opposite of what I was expecting:
> x86_64 complains with (-1LL) cast while I was expecting it to fail on (-1L)
> i686 complains with (-1L) cast while I was expecting it to fail on (-1LL)
> 

I think it is best to check with gcc-help what the correct behavior is.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 858 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast
@ 2017-10-23 14:47 Paolo ZAMBOTTI
  2017-10-23 23:26 ` JonY
  2017-10-24  9:19 ` Csaba Raduly
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo ZAMBOTTI @ 2017-10-23 14:47 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1657 bytes --]

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) ...

The attached file is the simplest example that triggers the issue.

If I try to compile with "x86_64-w64-mingw32-gcc -o test.exe test.cpp" the output is the following

test.cpp: In function 'int main(int, char**)':
test.cpp:7:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test2 = (void*)(-1LL);
                                  ^~~~~~~~~~~~~

While, if I try to compile with "i686-w64-mingw32-gcc -o test.exe test.cpp" the output is the following

test.cpp: In function 'int main(int, char**)':
test.cpp:12:34: error: reinterpret_cast from integer to pointer
   static constexpr void* test2 = (void*)(-1L);
                                  ^~~~~~~~~~~~

The test is effectively build to always fail but the current behavior is exactly the opposite of what I was expecting:
x86_64 complains with (-1LL) cast while I was expecting it to fail on (-1L)
i686 complains with (-1L) cast while I was expecting it to fail on (-1LL)


Just to complete the picture, my environment is:
Windows 7 machine
Latest Cygwin (updated today 23 -Oct-2017)

Regards,
Paolo.

[-- Attachment #2: test.cpp --]
[-- Type: text/plain, Size: 387 bytes --]

#include <windows.h>
#include <stdio.h>

int main (int argc, char **argv) {
#ifdef _WIN64 
  static constexpr void* test1 = (void*)(-1L);
  static constexpr void* test2 = (void*)(-1LL);

  printf("%llx, %llx\n", test1, test2);
#else
  static constexpr void* test1 = (void*)(-1LL);
  static constexpr void* test2 = (void*)(-1L);

  printf("%lx, %lx\n", test1, test2);
#endif

return 0;

}

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-01 14:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31 10:01 cygwin x86_64: mingw64-g++ 6.4.0 (both i686 and x86_64) issue (bug?) with reinterpret_cast Paolo ZAMBOTTI
2017-11-01 14:25 ` Csaba Raduly
  -- strict thread matches above, loose matches on Subject: below --
2017-10-23 14:47 Paolo ZAMBOTTI
2017-10-23 23:26 ` JonY
2017-10-24  9:19 ` Csaba Raduly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).