summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-03-27 16:19:29 +0200
committerKent Hansen <kent.hansen@nokia.com>2012-03-27 19:22:48 +0200
commitd236fe2214340164bec4f34cb27dea4a634ee0de (patch)
treecda4ebbcc91717b37e5a2dbccb9ee46c2a1d3885 /src/corelib/global
parent2b17b0235b70f89d15d3b91a14c3297d38377f94 (diff)
parentcbc883da6910b3357a4e03d0e2dfa841da1a03e8 (diff)
Merge master into api_changes
Conflicts: src/corelib/global/qisenum.h src/dbus/qdbusconnection_p.h src/widgets/kernel/qwidget.cpp tests/auto/other/qaccessibility/tst_qaccessibility.cpp Change-Id: I85102515d5fec835832cc20ffdc5c1ba578bd01d
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qcompilerdetection.h164
-rw-r--r--src/corelib/global/qglobal.cpp57
-rw-r--r--src/corelib/global/qglobal.h27
-rw-r--r--src/corelib/global/qisenum.h6
4 files changed, 188 insertions, 66 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index b3787261be..c9f59454b2 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Intel Corporation
** Contact: http://www.qt-project.org/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -87,6 +88,8 @@
# define Q_NO_TEMPLATE_FRIENDS
# define Q_ALIGNOF(type) __alignof(type)
# define Q_DECL_ALIGN(n) __declspec(align(n))
+# define Q_ASSUME(expr) __assume(expr)
+# define Q_UNREACHABLE() __assume(0)
/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
# if defined(__INTEL_COMPILER)
# define Q_CC_INTEL
@@ -140,11 +143,19 @@
# if defined(__INTEL_COMPILER)
/* Intel C++ also masquerades as GCC */
# define Q_CC_INTEL
-# endif
-# if defined(__clang__)
+# define Q_ASSUME(expr) __assume(expr)
+# define Q_UNREACHABLE() __assume(0)
+# elif defined(__clang__)
/* Clang also masquerades as GCC */
# define Q_CC_CLANG
+# define Q_ASSUME(expr) if (expr){} else __builtin_unreachable()
+# define Q_UNREACHABLE() __builtin_unreachable()
+# else
+/* Plain GCC */
+# define Q_ASSUME(expr) if (expr){} else __builtin_unreachable()
+# define Q_UNREACHABLE() __builtin_unreachable()
# endif
+
# define Q_ALIGNOF(type) __alignof__(type)
# define Q_TYPEOF(expr) __typeof__(expr)
# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n)))
@@ -157,45 +168,9 @@
# define QT_NO_ARM_EABI
# endif
# endif
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 && !defined(Q_CC_CLANG)
# define Q_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
# endif
-# if defined(__GXX_EXPERIMENTAL_CXX0X__) && !defined(__clang__) /* clang C++11 enablers are found below, don't do them here */
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
- /* C++0x features supported in GCC 4.3: */
-# define Q_COMPILER_VARIADIC_MACROS
-# define Q_COMPILER_RVALUE_REFS
-# define Q_COMPILER_DECLTYPE
-# define Q_COMPILER_STATIC_ASSERT
-# endif
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404
- /* C++0x features supported in GCC 4.4: */
-# define Q_COMPILER_UNICODE_STRINGS
-# define Q_COMPILER_VARIADIC_TEMPLATES
-# define Q_COMPILER_AUTO_TYPE
-# define Q_COMPILER_EXTERN_TEMPLATES
-# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
-# define Q_COMPILER_CLASS_ENUM
-# define Q_COMPILER_INITIALIZER_LISTS
-# define Q_COMPILER_ATOMICS
-# endif
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
- /* C++0x features supported in GCC 4.5: */
-# define Q_COMPILER_LAMBDA
-# endif
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
- /* C++0x features supported in GCC 4.6: */
-# define Q_COMPILER_NULLPTR
-# define Q_COMPILER_CONSTEXPR
-# define Q_COMPILER_UNRESTRICTED_UNIONS
-# define Q_COMPILER_RANGE_FOR
-# endif
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407
- /* C++0x features supported in GCC 4.7: */
-# define Q_COMPILER_EXPLICIT_OVERRIDES
-# endif
-
-# endif
/* IBM compiler versions are a bit messy. There are actually two products:
the C product, and the C++ product. The C++ compiler is always packaged
@@ -420,22 +395,66 @@
# error "Qt has not been tested with this compiler - see http://www.qt-project.org/"
#endif
+/*
+ * C++11 support
+ *
+ * Paper Macro
+ * N2341 Q_COMPILER_ALIGNAS
+ * N2341 Q_COMPILER_ALIGNOF
+ * N2427 Q_COMPILER_ATOMICS
+ * N2761 Q_COMPILER_ATTRIBUTES
+ * N2541 Q_COMPILER_AUTO_FUNCTION
+ * N1984 N2546 Q_COMPILER_AUTO_TYPE
+ * N2437 Q_COMPILER_CLASS_ENUM
+ * N2235 N3276 Q_COMPILER_DECLTYPE
+ * N2346 Q_COMPILER_DEFAULT_DELETE_MEMBERS
+ * N1986 Q_COMPILER_DELEGATING_CONSTRUCTORS
+ * N3206 N3272 Q_COMPILER_EXPLICIT_OVERRIDES (v0.9 and above only)
+ * N1987 Q_COMPILER_EXTERN_TEMPLATES
+ * N2540 Q_COMPILER_INHERITING_CONSTRUCTORS
+ * N2672 Q_COMPILER_INITIALIZER_LISTS
+ * N2658 N2927 Q_COMPILER_LAMBDA (v1.0 and above only)
+ * N2756 Q_COMPILER_NONSTATIC_MEMBER_INIT
+ * N2431 Q_COMPILER_NULLPTR
+ * N2930 Q_COMPILER_RANGE_FOR
+ * N2442 Q_COMPILER_RAW_STRINGS
+ * N2439 Q_COMPILER_REF_QUALIFIERS
+ * N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS (Note: GCC 4.3 implements only the oldest)
+ * N1720 Q_COMPILER_STATIC_ASSERT
+ * N2258 Q_COMPILER_TEMPLATE_ALIAS
+ * N2659 Q_COMPILER_THREAD_LOCAL
+ * N2756 Q_COMPILER_UDL
+ * N2442 Q_COMPILER_UNICODE_STRINGS
+ * N2544 Q_COMPILER_UNRESTRICTED_UNIONS
+ * N1653 Q_COMPILER_VARIADIC_MACROS
+ * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES
+ */
#ifdef Q_CC_INTEL
# if __INTEL_COMPILER < 1200
# define Q_NO_TEMPLATE_FRIENDS
# endif
-# if defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__)
+# if defined(_CHAR16T) || __cplusplus >= 201103L
+# define Q_COMPILER_VARIADIC_MACROS
# if __INTEL_COMPILER >= 1200
-# define Q_COMPILER_RVALUE_REFS
-# define Q_COMPILER_EXTERN_TEMPLATES
-# define Q_COMPILER_DECLTYPE
-# define Q_COMPILER_VARIADIC_TEMPLATES
# define Q_COMPILER_AUTO_TYPE
-# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
# define Q_COMPILER_CLASS_ENUM
+# define Q_COMPILER_DECLTYPE
+# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
+# define Q_COMPILER_EXTERN_TEMPLATES
# define Q_COMPILER_LAMBDA
+# define Q_COMPILER_RVALUE_REFS
# define Q_COMPILER_STATIC_ASSERT
+# define Q_COMPILER_THREAD_LOCAL
+# define Q_COMPILER_VARIADIC_MACROS
+# endif
+# if __INTEL_COMPILER >= 1210
+# define Q_COMPILER_ATTRIBUTES
+# define Q_COMPILER_AUTO_FUNCTION
+# define Q_COMPILER_NULLPTR
+# define Q_COMPILER_TEMPLATE_ALIAS
+# define Q_COMPILER_UNICODE_STRINGS
+# define Q_COMPILER_VARIADIC_TEMPLATES
# endif
# endif
#endif
@@ -463,6 +482,7 @@
# define Q_COMPILER_CLASS_ENUM
/* defaulted members in 3.0, deleted members in 2.9 */
# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
+# define Q_COMPILER_DELEGATING_CONSTRUCTORS
# define Q_COMPILER_EXPLICIT_OVERRIDES
# define Q_COMPILER_NULLPTR
# define Q_COMPILER_RANGE_FOR
@@ -487,6 +507,60 @@
# endif
#endif // Q_CC_CLANG
+#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
+# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
+ /* C++11 features supported in GCC 4.3: */
+# define Q_COMPILER_DECLTYPE
+# define Q_COMPILER_RVALUE_REFS
+# define Q_COMPILER_STATIC_ASSERT
+# define Q_COMPILER_VARIADIC_MACROS
+# endif
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404
+ /* C++11 features supported in GCC 4.4: */
+# define Q_COMPILER_ATOMICS
+# define Q_COMPILER_AUTO_FUNCTION
+# define Q_COMPILER_AUTO_TYPE
+# define Q_COMPILER_CLASS_ENUM
+# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
+# define Q_COMPILER_EXTERN_TEMPLATES
+# define Q_COMPILER_INITIALIZER_LISTS
+# define Q_COMPILER_UNICODE_STRINGS
+# define Q_COMPILER_VARIADIC_TEMPLATES
+# endif
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
+ /* C++11 features supported in GCC 4.5: */
+# define Q_COMPILER_LAMBDA
+# define Q_COMPILER_RAW_STRINGS
+# endif
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
+ /* C++11 features supported in GCC 4.6: */
+# define Q_COMPILER_CONSTEXPR
+# define Q_COMPILER_NULLPTR
+# define Q_COMPILER_UNRESTRICTED_UNIONS
+# define Q_COMPILER_RANGE_FOR
+# endif
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407
+ /* C++11 features supported in GCC 4.7: */
+# define Q_COMPILER_NONSTATIC_MEMBER_INIT
+# define Q_COMPILER_DELEGATING_CONSTRUCTORS
+# define Q_COMPILER_EXPLICIT_OVERRIDES
+# define Q_COMPILER_TEMPLATE_ALIAS
+# define Q_COMPILER_UDL
+# endif
+# endif
+#endif
+
+#if defined(Q_CC_MSVC) && _MSC_VER >= 1600 && !defined(Q_CC_INTEL)
+# define Q_COMPILER_AUTO_TYPE
+# define Q_COMPILER_LAMBDA
+# define Q_COMPILER_DECLTYPE
+# define Q_COMPILER_RVALUE_REFS
+# define Q_COMPILER_STATIC_ASSERT
+// MSVC has std::initilizer_list, but does not support the braces initialization
+//# define Q_COMPILER_INITIALIZER_LISTS
+#endif
+
#ifndef Q_COMPILER_MANGLES_RETURN_TYPE
# if defined(Q_CC_MSVC)
# define Q_COMPILER_MANGLES_RETURN_TYPE
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 09d178639d..f89b0b3421 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1799,6 +1799,63 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion()
*/
/*!
+ \macro void Q_ASSUME(bool expr)
+ \relates <QtGlobal>
+ \since 5.0
+
+ Causes the compiler to assume that \a expr is true. This macro is useful
+ for improving code generation, by providing the compiler with hints about
+ conditions that it would not otherwise know about. However, there is no
+ guarantee that the compiler will actually use those hints.
+
+ This macro could be considered a "lighter" version of \ref Q_ASSERT. While
+ Q_ASSERT will abort the program's execution if the condition is false,
+ Q_ASSUME will tell the compiler not to generate code for those conditions.
+ Therefore, it is important that the assumptions always hold, otherwise
+ undefined behaviour may occur.
+
+ If \a expr is a constantly false condition, Q_ASSUME will tell the compiler
+ that the current code execution cannot be reached. That is, Q_ASSUME(false)
+ is equivalent to Q_UNREACHABLE().
+
+ \note Q_LIKELY() tells the compiler that the expression is likely, but not
+ the only possibility. Q_ASSUME tells the compiler that it is the only
+ possibility.
+
+ \sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
+*/
+
+/*!
+ \macro void Q_UNREACHABLE()
+ \relates <QtGlobal>
+ \since 5.0
+
+ Tells the compiler that the current point cannot be reached by any
+ execution, so it may optimise any code paths leading here as dead code, as
+ well as code continuing from here.
+
+ This macro is useful to mark impossible conditions. For example, given the
+ following enum:
+
+ \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-enum
+
+ One can write a switch table like so:
+
+ \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunreachable-switch
+
+ The advantage of inserting Q_UNREACHABLE() at that point is that the
+ compiler is told not to generate code for a shape variable containing that
+ value. If the macro is missing, the compiler will still generate the
+ necessary comparisons for that value. If the case label were removed, some
+ compilers could produce a warning that some enum values were not checked.
+
+ By using this macro in impossible conditions, code coverage may be improved
+ as dead code paths may be eliminated.
+
+ \sa Q_ASSERT(), Q_ASSUME(), qFatal()
+*/
+
+/*!
\macro void Q_CHECK_PTR(void *pointer)
\relates <QtGlobal>
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index ee577a7563..24e05fc72c 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -163,6 +163,12 @@ namespace QT_NAMESPACE {}
#ifndef Q_UNLIKELY
# define Q_UNLIKELY(x) (x)
#endif
+#ifndef Q_ASSUME
+# define Q_ASSUME(expr)
+#endif
+#ifndef Q_UNREACHABLE
+# define Q_UNREACHABLE()
+#endif
#ifndef Q_ALLOC_SIZE
# define Q_ALLOC_SIZE(x)
@@ -476,6 +482,10 @@ QT_END_INCLUDE_NAMESPACE
# define Q_DECL_FINAL_CLASS
#endif
+#if defined(Q_COMPILER_ALIGNOF) && !defined(Q_ALIGNOF)
+# define Q_ALIGNOF(x) alignof(x)
+#endif
+
//defines the type for the WNDPROC on windows
//the alignment needs to be forced for sse2 to not crash with mingw
#if defined(Q_OS_WIN)
@@ -866,7 +876,7 @@ Q_CORE_EXPORT bool qSharedBuild();
Avoid "unused parameter" warnings
*/
-#if defined(Q_CC_INTEL) && !defined(Q_OS_WIN) || defined(Q_CC_RVCT)
+#if defined(Q_CC_RVCT)
template <typename T>
inline void qUnused(T &x) { (void)x; }
# define Q_UNUSED(x) qUnused(x);
@@ -1355,20 +1365,7 @@ template <typename T>
inline const QForeachContainer<T> *qForeachContainer(const QForeachContainerBase *base, const T *)
{ return static_cast<const QForeachContainer<T> *>(base); }
-#if defined(Q_CC_MIPS)
-/*
- Proper for-scoping in MIPSpro CC
-*/
-# define Q_FOREACH(variable,container) \
- if(0){}else \
- for (const QForeachContainerBase &_container_ = qForeachContainerNew(container); \
- qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition(); \
- ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i) \
- for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
- qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk; \
- --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
-
-#elif defined(Q_CC_DIAB)
+#if defined(Q_CC_DIAB)
// VxWorks DIAB generates unresolvable symbols, if container is a function call
# define Q_FOREACH(variable,container) \
if(0){}else \
diff --git a/src/corelib/global/qisenum.h b/src/corelib/global/qisenum.h
index ef1ccc81a8..53b856e1c2 100644
--- a/src/corelib/global/qisenum.h
+++ b/src/corelib/global/qisenum.h
@@ -44,9 +44,6 @@
#ifndef QISENUM_H
#define QISENUM_H
-QT_BEGIN_HEADER
-QT_BEGIN_NAMESPACE
-
#ifndef Q_IS_ENUM
# if defined(Q_CC_GNU) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
# define Q_IS_ENUM(x) __is_enum(x)
@@ -64,7 +61,4 @@ QT_BEGIN_NAMESPACE
# define Q_IS_ENUM(x) QtPrivate::is_enum<x>::value
#endif
-QT_END_HEADER
-QT_END_NAMESPACE
-
#endif // QISENUM_H