summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/archdetect.cpp2
-rw-r--r--src/corelib/global/qcompilerdetection.h2
-rw-r--r--src/corelib/global/qendian.h1
-rw-r--r--src/corelib/global/qglobal.cpp79
-rw-r--r--src/corelib/global/qglobal.h2
-rw-r--r--src/corelib/global/qglobalstatic.cpp2
-rw-r--r--src/corelib/global/qglobalstatic.h2
-rw-r--r--src/corelib/global/qlibraryinfo.cpp2
-rw-r--r--src/corelib/global/qlogging.cpp4
-rw-r--r--src/corelib/global/qnumeric_p.h2
-rw-r--r--src/corelib/global/qprocessordetection.h1
-rw-r--r--src/corelib/global/qsysinfo.h1
-rw-r--r--src/corelib/global/qtypeinfo.h1
-rw-r--r--src/corelib/global/qversiontagging.cpp2
-rw-r--r--src/corelib/global/qversiontagging.h2
15 files changed, 91 insertions, 14 deletions
diff --git a/src/corelib/global/archdetect.cpp b/src/corelib/global/archdetect.cpp
index 35db0875e5..8a88c2f5c8 100644
--- a/src/corelib/global/archdetect.cpp
+++ b/src/corelib/global/archdetect.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Intel Corporation
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the FOO module of the Qt Toolkit.
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 21040dde38..eec8b5223b 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Intel Corporation
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h
index 69e67e2523..c5ff82c10a 100644
--- a/src/corelib/global/qendian.h
+++ b/src/corelib/global/qendian.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index c02528491e..1227445f1e 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2015 Intel Corporation
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -3540,7 +3540,11 @@ int qrand()
\snippet code/src_corelib_global_qglobal.cpp 33
- \sa Q_FOREACH()
+ \note Since Qt 5.7, the use of this macro is discouraged. It will
+ be removed in a future version of Qt. Please use C++11 range-for,
+ possibly with qAsConst(), as needed.
+
+ \sa qAsConst()
*/
/*!
@@ -3552,7 +3556,76 @@ int qrand()
This macro is available even when \c no_keywords is specified
using the \c .pro file's \c CONFIG variable.
- \sa foreach()
+ \note Since Qt 5.7, the use of this macro is discouraged. It will
+ be removed in a future version of Qt. Please use C++11 range-for,
+ possibly with qAsConst(), as needed.
+
+ \sa qAsConst()
+*/
+
+/*!
+ \fn qAsConst(T &t)
+ \relates <QtGlobal>
+ \since 5.7
+
+ Returns \a t cast to \c{const T}.
+
+ This function is a Qt implementation of C++17's std::as_const(),
+ a cast function like std::move(). But while std::move() turns
+ lvalues into rvalues, this function turns non-const lvalues into
+ const lvalues. Like std::as_const(), it doesn't work on rvalues,
+ because it cannot be efficiently implemented for rvalues without
+ leaving dangling references.
+
+ Its main use in Qt is to prevent implicitly-shared Qt containers
+ from detaching:
+ \code
+ QString s = ...;
+ for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
+ process(ch);
+ for (QChar ch : qAsConst(s)) // ok, no detach attempt
+ process(ch);
+ \endcode
+
+ Of course, in this case, you could (and probably should) have declared
+ \c s as \c const in the first place:
+ \code
+ const QString s = ...;
+ for (QChar ch : s) // ok, no detach attempt on const objects
+ process(ch);
+ \endcode
+ but often that is not easily possible.
+
+ It is important to note that qAsConst() does not copy its argument,
+ it just performs a \c{const_cast<const T&>(t)}. This is also the reason
+ why it is designed to fail for rvalues: The returned reference would go
+ stale too soon. So while this works (but detaches the returned object):
+ \code
+ for (QChar ch : funcReturningQString())
+ process(ch); // OK, the returned object is kept alive for the loop's duration
+ \endcode
+
+ this would not:
+ \code
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+ \endcode
+
+ To prevent this construct from compiling (and failing at runtime), qAsConst() has
+ a second, deleted, overload which binds to rvalues.
+*/
+
+/*!
+ \fn qAsConst(const T &&t)
+ \relates <QtGlobal>
+ \since 5.7
+ \overload
+
+ This overload is deleted to prevent a dangling reference in code like
+ \code
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+ \endcode
*/
/*!
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 2025758522..69840996dc 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Intel Corporation.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qglobalstatic.cpp b/src/corelib/global/qglobalstatic.cpp
index 84ed82694d..d1c522a79a 100644
--- a/src/corelib/global/qglobalstatic.cpp
+++ b/src/corelib/global/qglobalstatic.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Intel Corporation.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h
index 507897880c..4fb3c4f91f 100644
--- a/src/corelib/global/qglobalstatic.h
+++ b/src/corelib/global/qglobalstatic.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Intel Corporation
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index ebb52acd58..ce838622bc 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Intel Corporation
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 94a2864041..2441de16cd 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1,8 +1,8 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
-** Copyright (C) 2014 Intel Corporation.
+** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h
index b32f63c5f5..f58e062dbd 100644
--- a/src/corelib/global/qnumeric_p.h
+++ b/src/corelib/global/qnumeric_p.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2015 Intel Corporation.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h
index 0f258f75cf..8c1e041a17 100644
--- a/src/corelib/global/qprocessordetection.h
+++ b/src/corelib/global/qprocessordetection.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h
index d5d6fd760c..b74fc80468 100644
--- a/src/corelib/global/qsysinfo.h
+++ b/src/corelib/global/qsysinfo.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h
index 559499476e..2b4f6ebab4 100644
--- a/src/corelib/global/qtypeinfo.h
+++ b/src/corelib/global/qtypeinfo.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qversiontagging.cpp b/src/corelib/global/qversiontagging.cpp
index 60edd79c7f..e3d4037a16 100644
--- a/src/corelib/global/qversiontagging.cpp
+++ b/src/corelib/global/qversiontagging.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 Intel Corporation.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/global/qversiontagging.h b/src/corelib/global/qversiontagging.h
index 60fc46f035..706e7e07ff 100644
--- a/src/corelib/global/qversiontagging.h
+++ b/src/corelib/global/qversiontagging.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 Intel Corporation.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.