Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler warning on MinGW gcc 8.1.0 #1619

Closed
man4 opened this issue May 30, 2018 · 7 comments
Closed

Compiler warning on MinGW gcc 8.1.0 #1619

man4 opened this issue May 30, 2018 · 7 comments

Comments

Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
@man4
Copy link

@man4 man4 commented May 30, 2018

I'm getting the following compiler warning on MinGW, gcc 8.1.0 (which didn't appear in gcc 7.3.0):

misc.cpp: In function 'int WinProcGroup::get_group(size_t)':
misc.cpp:241:77: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'fun1_t' {aka 'bool (*)(_LOGICAL_PROCESSOR_RELATIONSHIP, _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*, long unsigned int*)'} [-Wcast-function-type]
   auto fun1 = (fun1_t)GetProcAddress(k32, "GetLogicalProcessorInformationEx");
                                                                             ^
misc.cpp: In function 'void WinProcGroup::bindThisThread(size_t)':
misc.cpp:309:71: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'fun2_t' {aka 'bool (*)(short unsigned int, _GROUP_AFFINITY*)'} [-Wcast-function-type]
   auto fun2 = (fun2_t)GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
                                                                       ^
misc.cpp:310:67: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'fun3_t' {aka 'bool (*)(void*, const _GROUP_AFFINITY*, _GROUP_AFFINITY*)'} [-Wcast-function-type]
   auto fun3 = (fun3_t)GetProcAddress(k32, "SetThreadGroupAffinity");

According to the release notes for gcc 8, the option -Wextra is responsible for this warning.

@Hanamuke
Copy link

@Hanamuke Hanamuke commented Jun 1, 2018

That should be easy to fix but i don't have an msvc compiler, maybe @mstembera can help ?

@mstembera
Copy link

@mstembera mstembera commented Jun 1, 2018

@Hanamuke These are Mingw/gcc 8.1.0 warnings not msvc.

@syzygy1
Copy link

@syzygy1 syzygy1 commented Jun 1, 2018

I think it's a rather stupid warning of gcc. I don't think there is any "right" way to do the cast that does not result in bogus warnings. (Feel free to prove me wrong, though!)

It is possible (at least in C) to cast first to void (*)(void), then to the desired type, but in my view that is just a hack.

@WOnder93
Copy link

@WOnder93 WOnder93 commented Jun 1, 2018

In C++, I think one should use static_cast<...>(...) or even reinterpret_cast<...>(...) in this situation.

mstembera pushed a commit to mstembera/Stockfish that referenced this issue Jun 12, 2018
official-stockfish#1619

No functional change.
bench: 4980482
@snicolet
Copy link
Member

@snicolet snicolet commented Jun 12, 2018

The gcc 8 release notes ( https://gcc.gnu.org/gcc-8/changes.html ) indicate that there is a new flag -Wold-style-cast to get help for how to deal with casting problems: "The -Wold-style-cast diagnostic can now emit fix-it hints telling you when you can use a static_cast, const_cast, or reinterpret_cast."

==> @man4 , @mstembera If you have access to gcc 8, could you try to edit the makefile and compile the current master with -Wold-style-cast to see the diagnostic the compiler emits? Thanks in advance.

@man4
Copy link
Author

@man4 man4 commented Jun 13, 2018

Here are the relevant warnings:

misc.cpp:241:77: warning: use of old-style cast to 'fun1_t' {aka 'bool (*)(enum _LOGICAL_PROCESSOR_RELATIONSHIP, struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*, long unsigned int*)'} [-Wold-style-cast]
   auto fun1 = (fun1_t)GetProcAddress(k32, "GetLogicalProcessorInformationEx");
                                                                             ^
               --------
               reinterpret_cast<fun1_t> (                                     )

misc.cpp:309:71: warning: use of old-style cast to 'fun2_t' {aka 'bool (*)(short unsigned int, struct _GROUP_AFFINITY*)'} [-Wold-style-cast]
   auto fun2 = (fun2_t)GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
                                                                       ^
               --------
               reinterpret_cast<fun2_t> (                               )

misc.cpp:310:67: warning: use of old-style cast to 'fun3_t' {aka 'bool (*)(void*, const struct _GROUP_AFFINITY*, struct _GROUP_AFFINITY*)'} [-Wold-style-cast]
   auto fun3 = (fun3_t)GetProcAddress(k32, "SetThreadGroupAffinity");
                                                                   ^
               --------
               reinterpret_cast<fun3_t> (                           )

I've attached the full stderr output too (which contains warnings for all old-style casts):
out.txt

I tried naively changing all the casts to reinterpret_cast<...>(...) but the incompatible function type warning still appears. Indeed, the warning seems unrelated to the fact that old-style casting was used.

@man4
Copy link
Author

@man4 man4 commented Jun 13, 2018

It is possible (at least in C) to cast first to void (*)(void), then to the desired type, but in my view that is just a hack.

Changing (fun1_t) to (fun1_t)(void(*)()) (and similarly for the other casts) does remove the warnings in gcc 8, but I agree with @syzygy1 that this looks ugly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment