https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113465

--- Comment #4 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Andrew Pinski from comment #3)
> See PR 54483 .
> 
> *** This bug has been marked as a duplicate of bug 54483 ***

I don't think that's the same. That situation over there is C++11, where the
constexpr variable is *not* static.

I forgot to say that in my case it is inline because it's C++17.

On use, GCC emits a copy of the variable:
struct __declspec(dllimport) QLocale
{
    static constexpr inline int FirstTwoDigitYear = 1900;
};

template<typename T> void f(const T &);
void f() { f(QLocale::FirstTwoDigitYear); }

results in:

_Z1fv:
        movq    __imp__ZN7QLocale17FirstTwoDigitYearE(%rip), %rcx
        jmp     _Z1fIiEvRKT_
_ZN7QLocale17FirstTwoDigitYearE:
        .long   1900

This copy is useless. The equivalent code for ELF and Mach-O ABIs is fine
because the relocation would find it, if the original variable doesn't exist in
the .so. But on Windows, that __imp_ prefix implies it's an import from another
DLL, which *must* have emitted its copy and exported it.

Clang and MSVC also do the import, but don't emit that copy. See
https://mingw.godbolt.org/z/aKsaYKThT.

Reply via email to