See http://bugreports.qt.io/browse/QTBUG-121135 for the issue and
https://codereview.qt-project.org/c/qt/qtbase/+/531251 for the solution.

TL;DR: if you define a static constexpr (which is implicitly inline) member 
variable in a class with export macro, you MUST add the definition of tha 
variable to the .cpp.

Alternatives:
* move to a class that is not exported
   trick: add an empty base with the variable
* change to enum (if primitive)

But this happens even for plain int variables. For example:

#include <vector>
#include <QtCore/qlocale.h>
void f(std::vector<int> &v) 
{ 
    v.push_back(QLocale::FirstTwoDigitYear);
}

This produced: with GCC 13 at -O2 optimisations:

_Z1fRSt6vectorIiSaIiEE:
        movq    8(%rcx), %rdx
        cmpq    16(%rcx), %rdx
        je      .L29
        movl    $1900, (%rdx)
        addq    $4, %rdx
        movq    %rdx, 8(%rcx)
        ret
.L29:
        movq    __imp__ZN7QLocale17FirstTwoDigitYearE(%rip), %r8
        jmp     
_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_

Interpretation: if the vector has enough pre-allocated space, it simply moves 
1900 to the end of te array and adjusts the end. But if not, it calls 
std::vector::::_M_realloc_insert(), which takes the integer by reference, so 
the compiler emits an import from the DLL.

This appears to be a GCC bug/shortcoming. Clang and MSVC apparently 
automatically emit and export the variable for you:
https://mingw.godbolt.org/z/q4dYdosjh

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering

Attachment: smime.p7s
Description: S/MIME cryptographic signature

-- 
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to