Work around a binary incompatibility in MSVC

The fix in b8fe5e1bbc (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>
This commit is contained in:
Thiago Macieira 2014-01-22 11:13:44 -08:00 committed by The Qt Project
parent c695543f76
commit 614589d844
3 changed files with 63 additions and 2 deletions

View File

@ -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; }

View File

@ -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>

View File

@ -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: {