在 2020/3/19 20:35, Martin Storsjö 写道:
> For C++, the generated .h encloses this block in 'extern "C" { .. }'
> anyway, and as these are variable definitions (with DECLSPEC_SELECTANY,
> avoiding duplicate definitions even though it's in a header), not
> declarations, GCC (and possibly clang as well) warn when the definition
> also contains the 'extern' attribute.
>
> This fixes the same warning as d551b7d85ec63c0fa33f1a51ec5157722709fc53
> tried to fix, without overriding the EXTERN_C macro, which affected
> other headers.
>
> Signed-off-by: Martin Storsjö <[email protected]>
> ---
>
The first patch looks good - but it can't be pushed unless we find a
workaround for this issue.
In C++ a variable (object or reference) having namespace scope and being
declared with `const` and without `volatile` or `extern` has internal
linkage (as if it was declared `static const`) [1]. This is true
regardless whether it is inside an `extern "C"` block or not.
If these constant objects had internal linkage, then for example
`&MFPKEY_CLSID` in two different source files will yield two different
values due to duplication.
From my experience the best solution would look like this, which works
both in C and C++:
```
extern const PROPERTYKEY MFPKEY_CLSID;
// declaration with `extern`
DECLSPEC_SELECTANY const PROPERTYKEY MFPKEY_CLSID
= { ... }; // definition with `__selectany__`
```
But this requires the declarator to be written twice.
[1] https://en.cppreference.com/w/cpp/language/storage_duration
--
Best regards,
LH_Mouse
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
