summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-01-22 11:13:44 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-23 18:36:33 +0100
commit614589d844921e351e5422ba4a9b55aac22566c5 (patch)
treee8fed4feee59a8b4e43838621be8d12bd28cc522 /src/corelib/tools
parentc695543f76715f1f7acef32102c325399d0953cf (diff)
Work around a binary incompatibility in MSVC
The fix in b8fe5e1bbc7f341d03d2704a6110d6e3240589bb (for bug QTBUG-27277) created two sets of begin() and end() functions for QVector. That was required because QTypedArrayData::iterator and QTypedArrayData::const_iterator have non-implicit copy constructors, which means the variants returning a strict iterator need to pass the storage pointer as an implicit first parameter. With the fix, the compiler would emit functions with two different names for each variant, which couldn't be merged. If we remove those copy constructors, the compiler might be able to generate the same code (no implicit first parameter) for both functions. Now, enter MSVC. Due to QPolygon, QVector<QPoint> and QVector<QPointF> are "extern templates". That is, the compiler is not allowed to inline anything, it must generate calls into QtCore (which we must fix for Qt 6, if we can). That means QtCore would only have one set of begin() / end() functions. If an application tried to use the other set by defining QT_STRICT_ITERATORS, you'd get a linker error for: ?begin@?$QVector@VQPoint@@@@QEAA?AViterator@?$QTypedArrayData@VQPoint@@@@V23@@Z (class QTypedArrayData<class QPoint>::iterator QGenericArray<class QPoint>::begin(class QTypedArrayData<class QPoint>::iterator)) Change-Id: I5c10a7d0a4855f4ba84056d313c6a800ecdcfe37 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydata.h4
-rw-r--r--src/corelib/tools/qvector_msvc.cpp60
-rw-r--r--src/corelib/tools/tools.pri1
3 files changed, 63 insertions, 2 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 27f2606954..7df4694bcd 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -142,7 +142,7 @@ struct QTypedArrayData
inline iterator() : i(0) {}
inline iterator(T *n) : i(n) {}
- inline iterator(const iterator &o): i(o.i){}
+ inline iterator(const iterator &o): i(o.i){} // #### Qt 6: remove, the implicit version is fine
inline T &operator*() const { return *i; }
inline T *operator->() const { return i; }
inline T &operator[](int j) const { return *(i + j); }
@@ -176,7 +176,7 @@ struct QTypedArrayData
inline const_iterator() : i(0) {}
inline const_iterator(const T *n) : i(n) {}
- inline const_iterator(const const_iterator &o): i(o.i) {}
+ inline const_iterator(const const_iterator &o): i(o.i) {} // #### Qt 6: remove, the default version is fine
inline explicit const_iterator(const iterator &o): i(o.i) {}
inline const T &operator*() const { return *i; }
inline const T *operator->() const { return i; }
diff --git a/src/corelib/tools/qvector_msvc.cpp b/src/corelib/tools/qvector_msvc.cpp
new file mode 100644
index 0000000000..8570fcf5fe
--- /dev/null
+++ b/src/corelib/tools/qvector_msvc.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Intel Corporation
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// ### Qt6: verify if we can remove this, somehow.
+// First, try to see if the extern template from qvector.h is necessary.
+// If it still is, check if removing the copy constructors in qarraydata.h
+// make the calling convention of both sets of begin() and end() functions
+// match, as it does for the IA-64 C++ ABI.
+
+#ifdef QVECTOR_H
+# error "This file must be compiled with no precompiled headers"
+#endif
+
+// invert the setting of QT_STRICT_ITERATORS, whichever it was
+#ifdef QT_STRICT_ITERATORS
+# undef QT_STRICT_ITERATORS
+#else
+# define QT_STRICT_ITERATORS
+#endif
+
+// the Q_TEMPLATE_EXTERN at the bottom of qvector.h will do the trick
+#include <QtCore/qvector.h>
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index a727315700..ba995b047d 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -115,6 +115,7 @@ SOURCES += \
tools/qvsnprintf.cpp
NO_PCH_SOURCES = tools/qstring_compat.cpp
+msvc: NO_PCH_SOURCES += tools/qvector_msvc.cpp
false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
!nacl:mac: {