summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-31 11:27:49 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-06-22 01:09:24 +0000
commit97f643faee876cadb36f110ef5a96abf1b68acff (patch)
tree93733217d1b04d3f8d343aac796c5b33aeaa5def /cmake
parent1a030f6609ad6a9bbc1253e9e2d5efb198dc5998 (diff)
Long live QT_INLINE_SINCE!
We have now had several requests for inlining previously-exported member functions, but no standard mechanism to effect it. As QT_REMOVED_SINCE has shown, there is great value in having such a standard mechanism, so here is one. With this change, to inline a previously exported (member) function, simply - mark the declaration with QT_<MODULE>_INLINE_SINCE - move the definition into the header file (outside the class), - wrap it in QT_<MODULE>_INLINE_IMPL_SINCE - #include the header into the module's removed_api.cpp Just including the header into removed_api.cpp is enough, so you may want to add a comment: #include "header.h" // uses QT_<MODULE>_INLINE_SINCE The effect is as follows: - A TU in a _different_ library will see an inline declaration, followed by the definition, and so it will see a normal inline function. - A TU in the same library will, however, see a non-inline declaration, to avoid the ODR violation that at least GCC/ld are able to detect. - When QT_<MODULE>_BUILD_REMOVED_API is in effect, the TU will also see the definition, which is the same setup as before the change, except in a different TU, and therefore export the member. - When, OTOH, QT_<MODULE>_BUILD_REMOVED_API is _not_ in effect, the TU will see no declaration, assuming (correctly), that the definition will be supplied by a different TU. This is, of course, an ODR violation, but not worse than what we do elsewhere, as the definitions differ only between library and user. The function is inline only for the users of the library, not the library itself, which will still see the function as non-inline. If inlining is critical within the library, too, the existing function should call a new inline function, and calls in the same library should be changed to call the new inline function instead. Use the new mechanism to inline the QLocale ctor we intended to inline for 6.3, but couldn't, because we hadn't found the magic incantation, yet. Thiago found it a few weeks later, and this is what this patch is based on. Fixes: QTBUG-100452 Pick-to: 6.4 Change-Id: Ia0030cddc64b6b92edfed860170d5204aa74b953 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modulecppexports.h.in14
1 files changed, 14 insertions, 0 deletions
diff --git a/cmake/modulecppexports.h.in b/cmake/modulecppexports.h.in
index a126dea0ec..a2c2155720 100644
--- a/cmake/modulecppexports.h.in
+++ b/cmake/modulecppexports.h.in
@@ -16,6 +16,20 @@
# define Q_@module_define_infix@_EXPORT
#endif
+#if !defined(QT_BUILD_@module_define_infix@_LIB) || defined(QT_STATIC)
+/* outside library → inline decl + defi */
+# define QT_@module_define_infix@_INLINE_SINCE(major, minor) inline
+# define QT_@module_define_infix@_INLINE_IMPL_SINCE(major, minor) 1
+#elif defined(QT_@module_define_infix@_BUILD_REMOVED_API)
+/* inside library, inside removed_api.cpp → non-inline decl, defi */
+# define QT_@module_define_infix@_INLINE_SINCE(major, minor) /* not inline */
+# define QT_@module_define_infix@_INLINE_IMPL_SINCE(major, minor) 1
+#else
+/* inside library, outside removed_api.cpp → non-inline decl, no defi */
+# define QT_@module_define_infix@_INLINE_SINCE(major, minor) /* not inline */
+# define QT_@module_define_infix@_INLINE_IMPL_SINCE(major, minor) 0
+#endif
+
#ifdef QT_@module_define_infix@_BUILD_REMOVED_API
# define QT_@module_define_infix@_REMOVED_SINCE(major, minor) QT_DEPRECATED_SINCE(major, minor)
#else