[PATCH 1/5] avicap32: Define NONAMELESSUNION in files that include objidl.h.

Zebediah Figura z.figura12 at gmail.com
Wed Dec 18 10:10:31 CST 2019

On 12/17/19 2:47 PM, Alexandre Julliard wrote:
> Zebediah Figura <z.figura12 at gmail.com> writes:
>> On 12/17/19 12:42 PM, Alexandre Julliard wrote:
>>> Zebediah Figura <zfigura at codeweavers.com> writes:
>>>> On 12/17/19 11:37 AM, Alexandre Julliard wrote:
>>>>> Zebediah Figura <z.figura12 at gmail.com> writes:
>>>>>> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47710
>>>>>> Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
>>>>>> ---
>>>>>> This is not currently necessary, but will be with the prescribed solution for
>>>>>> bug 47710, viz. defining the type _STGMEDIUM_UNION.
>>>>> I'm not sure I understand what fix you are proposing, but if it requires
>>>>> Winelib users to also define NONAMELESSUNION I don't think it's a viable
>>>>> solution.
>>>> Essentially, this:
>>>> ---
>>>> diff --git a/include/objidl.idl b/include/objidl.idl
>>>> index a0ad1f6e01f..4c56c422747 100644
>>>> --- a/include/objidl.idl
>>>> +++ b/include/objidl.idl
>>>> @@ -1427,7 +1427,7 @@ interface IAdviseSink : IUnknown
>>>>     } GDI_OBJECT;
>>>>     typedef struct _userSTGMEDIUM {
>>>> -    union switch(DWORD tymed) u {
>>>> +    union _STGMEDIUM_UNION switch(DWORD tymed) u {
>>>>       case TYMED_NULL:     ;
>>>>       case TYMED_MFPICT:   wireHMETAFILEPICT hMetaFilePict;
>>>>       case TYMED_ENHMF:    wireHENHMETAFILE hHEnhMetaFile;
>>>> ---
>>>> Which causes warnings anywhere that nameless unions are used:
>>>> ---
>>>> In file included from ../../../wine/include/objbase.h:258,
>>>>                   from ../../../wine/include/ole2.h:25,
>>>>                   from ../../include/strmif.h:13,
>>>>                   from ../../../wine/dlls/wmcodecdspuuid/wmcodecdspuuid.c:22:
>>>> ../../include/objidl.h:6109:21: warning: declaration does not declare
>>>> anything
>>>>   6109 |     } DUMMYUNIONNAME;
>>> I'm afraid we'll have to find a different fix then.
>> I understand the difficulty, but I'm not sure what else we can
>> reasonably do here. As far as I can see either we have to throw C++
>> under the bus (i.e. close that bug as WONTFIX), or we have to add
>> specific differences into widl (or objidl.idl) for winelib, to avoid
>> violating the C spec. That either means making the structure type
>> anonymous (i.e. not defining _STGMEDIUM_UNION), which is not
>> particularly great (not that it's particularly likely anyone would want
>> to use the _STGMEDIUM_UNION type), or forcibly giving the union member a
>> name (which would also potentially require changes in winelib user code).
>> But maybe I'm missing another, more perfect option.
> If the issue is C++ code, this can be fixed by providing a different
> definition with judicious use of cpp_quote and #ifdef __cplusplus.
> If the issue is C code accessing the structure members, it would be OK
> to require that code to be modified. But we can't require modifying
> every file that happens to include the header without any interest in
> that specific structure.

Thanks, that helps.

I guess ultimately the issue is that Microsoft made a header that 
violates the C spec (big surprise, huh?) unless NONAMELESSUNION is 
defined. Microsoft's version of the header is fine for C++. Ours is fine 
for C but not C++; of course, it's also missing a type definition. (A 
type definition which probably only exists because of the aforementioned 
restriction on C++ code).

Probably the nicest thing to do is define _STGMEDIUM_UNION only when C++ 
is used. That shouldn't require any changes to existing users of the 
header. I'll send a patch.

More information about the wine-devel mailing list