Closed viboes closed 6 years ago
The unnamed structs are used by Windows SDK to achieve a specific binary layout and member access syntax. Naming the structs will change the syntax to access the members, so it will be a breaking change.
The only way I know to get rid of the warning is to silence it, but the option in the compiler message is -Wpedantic
, which is a blanket option, which supposedly corresponds to a list of more fine grained options. Do you know what specific option controls this warning?
Unfortunately not. Otherwise I would disable it independently.
If we can not do anything, please be free to close it as wontfix.
There is no specific switch in GCC, you should push/ignore/pop -Wpedantic
Clang -Wgnu-anonymous-struct
MSVC (before VS2017) C4094
https://msdn.microsoft.com/en-us/library/7y0f9tby.aspx
P.S: I do not know if it needs to be wrapped with __cplusplus < 201103L
check
Naming the structs will change the syntax to access the members, so it will be a breaking change.
What is the syntax that is used to access these members today? The following fails for me:
#include <boost/winapi/system.hpp>
int main()
{
boost::winapi::SYSTEM_INFO_ si = {};
si.wProcessorArchitecture;
}
According to MSDN it looks like this is the intended syntax. It may be MSVC-specific though, I don't know.
What does MSDN have to do with it? I'm asking what is the syntax that is currently supported by Winapi and that will supposedly be broken by naming the struct
. The above fails on MSVC, so it's not that.
The intended syntax is the same as for SYSTEM_INFO
from Windows SDK. MSDN article shows that wProcessorArchitecture
should be directly accessible as if a member of SYSTEM_INFO
. It does work like that on my end with the real SYSTEM_INFO
but not with the one from Boost.WinAPI. This is a bug, which I was not aware of before.
Strangely enough, the structure is declared the same way in Windows SDK 10 and it works there somehow.
DUMMYSTRUCTNAME
and DUMMYUNIONNAME
in the <windows.h>
definition are macros that expand to nothing (when nameless structs are supported), which is why the intended syntax works. (The macros expand to s
and u
otherwise.)
Winapi however uses DUMMYSTRUCTNAME
literally, it's not a macro. So the syntax to access the struct member would be
#include <boost/winapi/system.hpp>
int main()
{
boost::winapi::SYSTEM_INFO_ si = {};
si.DUMMYUNIONNAME.DUMMYSTRUCTNAME.wProcessorArchitecture;
}
which I doubt anyone ever used. :-)
You are however correct, adding a name to the struct itself (rather than the member) does break the syntax, so we can't fix the warning by changing the definition of SYSTEM_INFO_
.
Ah, those lovely macros in Windows SDK.
Should be fixed in https://github.com/boostorg/winapi/commit/f004b4753d6fee6f68c90cfc65b075fa0a33d092. Hopefully, this should also silence the warnings.
Thanks for alerting me about the syntax bug.
Confirmed warning-free on mingw g++ 7 now. Thanks.