https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113465
Bug ID: 113465 Summary: [mingw-w64] dllexported constexpr (inline) variables not automatically emitted Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: thiago at kde dot org Target Milestone: --- Related to explicit instantiation of templates bugs: Bug 89088, Bug 109380 though I'd argue that since that has a special syntax, it's different. Testcase: struct __declspec(dllexport) QLocale { static constexpr int FirstTwoDigitYear = 1900; }; With GCC, this produces: .file "example.cpp" .text .ident "GCC: (MinGW-W64 x86_64-ucrt-mcf-seh, built by Brecht Sanders) 13.1.0" That is, nothing. With Clang, that emits (simplified): .text .section .rdata$_ZN7QLocale17FirstTwoDigitYearE,"dr",discard,_ZN7QLocale17FirstTwoDigitYearE .globl _ZN7QLocale17FirstTwoDigitYearE # @_ZN7QLocale17FirstTwoDigitYearE .p2align 2, 0x0 _ZN7QLocale17FirstTwoDigitYearE: .long 1900 # 0x76c .section .drectve,"yni" .ascii " -export:_ZN7QLocale17FirstTwoDigitYearE,data" .addrsig MSVC also emits the variable, though how it causes the export to happen isn't clear. https://mingw.godbolt.org/z/ErbfdPaf8 This can be worked around by explicitly declaring the variable as if it were not inline (before C++17): constexpr int QLocale::FirstTwoDigitYear; However, since this isn't required in any other platform and other compilers on Windows don't require it either, developers are going to forget it. And very likely, this issue is going to show up only when users compile their code, depending on varying levels of optimisation and inlining.