summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-01-22 09:04:46 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-01-23 10:08:23 -0800
commit62de01bf178a2ce629cf64cc73edcd2d88d8eeba (patch)
tree820b3f0ffc2e7fc51d06f7aae26aa7e860ab2108
parent4b3d6be5f5a175a4c66b527eb2df49d62dc30056 (diff)
QString & QByteArray: ensure QT_NO_CAST_* are not defined on Windows
We can't have those macros defined while compiling the headers on Windows (mainly MSVC, but there are some corner cases that apply to MinGW too) because the inline functions must be emitted and added to the DLL export table. Trying to undefine (as qchar.cpp did) won't work in builds with PCH or in CMake Unified builds, because the headers in question will have already been included. So instead just #error out. qchar.cpp is #included in qstring.cpp so it no longer needs this. For Qt 7, we'll un-export the class (see next commit). Note: it's possible we only need a single .cpp including the headers and compiled without these macros for the export to kick in. That could be removed_api.cpp, because that can never be part of PCH or Unified sources. But I have not confirmed this is the case. Task-number: QTBUG-121356 Change-Id: I5dd50a1a7ca5424d9e7afffd17acba32fb27f1ca Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r--src/corelib/text/qbytearray.cpp8
-rw-r--r--src/corelib/text/qchar.cpp8
-rw-r--r--src/corelib/text/qstring.cpp5
3 files changed, 13 insertions, 8 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 1ff2721265..b13708752d 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -34,6 +34,14 @@
#include <algorithm>
+#ifdef Q_OS_WIN
+# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_FROM_BYTEARRAY))
+// MSVC requires this, but let's apply it to MinGW compilers too, just in case
+# error "This file cannot be compiled with QT_NO_CAST_{TO,FROM}_ASCII, " \
+ "otherwise some QByteArray functions will not get exported."
+# endif
+#endif
+
QT_BEGIN_NAMESPACE
Q_CONSTINIT const char QByteArray::_empty = '\0';
diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp
index 4175b6c849..0b44b83a88 100644
--- a/src/corelib/text/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -1,14 +1,6 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-// Don't define it while compiling this module, or USERS of Qt will
-// not be able to link.
-#ifdef QT_NO_CAST_FROM_ASCII
-# undef QT_NO_CAST_FROM_ASCII
-#endif
-#ifdef QT_NO_CAST_TO_ASCII
-# undef QT_NO_CAST_TO_ASCII
-#endif
#include "qchar.h"
#include "qdatastream.h"
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 6ebd7debed..af77f5d5d3 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -51,6 +51,11 @@
#ifdef Q_OS_WIN
# include <qt_windows.h>
+# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_TO_ASCII))
+// MSVC requires this, but let's apply it to MinGW compilers too, just in case
+# error "This file cannot be compiled with QT_NO_CAST_{TO,FROM}_ASCII, " \
+ "otherwise some QString functions will not get exported."
+# endif
#endif
#ifdef truncate