diff --git a/doc/global/qt-cpp-defines.qdocconf b/doc/global/qt-cpp-defines.qdocconf index 5c762083a27..c2a267d08e8 100644 --- a/doc/global/qt-cpp-defines.qdocconf +++ b/doc/global/qt-cpp-defines.qdocconf @@ -162,6 +162,7 @@ Cpp.ignoretokens += \ QT_FASTCALL \ QT_MUTEX_LOCK_NOEXCEPT \ QT_POPCOUNT_CONSTEXPR \ + QT_POST_CXX17_API_IN_EXPORTED_CLASS \ QT_SIZEPOLICY_CONSTEXPR \ QT_WARNING_DISABLE_DEPRECATED \ QT_WARNING_PUSH \ diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index f6add04fbab..1c17e8b7a04 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1206,6 +1206,26 @@ */ #define Q_WEAK_OVERLOAD template +/* + * If one wants to add functions that use post-C++17 APIs, one needs to: + * + * 1) make them fully inline; and + * 2) guard them using the necessary feature-testing macros. + * + * This decouples the C++ version used to build Qt with the one used by + * end-user applications; Qt and the application can either choose any C++ + * version. + * + * A problem arises on MSVC for member functions of exported classes. Client + * code that tries to use such a function will see it as exported, and simply + * try to consume the function's *symbol*. However, if Qt has been built in + * C++17, it won't have such a symbol, and linking will fail. + * + * The workaround: declare such functions as function templates. + * (Obviously a function template does not need this marker.) +*/ +#define QT_POST_CXX17_API_IN_EXPORTED_CLASS template + /* * Warning/diagnostic handling */