Link Here
|
1 |
commit bc620055c82a8ccae49144ad99bf9226d659f852 |
1 |
clang: Only enable Q_COMPILER_INITIALIZER_LISTS with libc++. |
2 |
Author: Raphael Kubo da Costa <rakuco@FreeBSD.org> |
|
|
3 |
Date: Sun Jul 13 23:15:00 2014 +0300 |
4 |
|
2 |
|
5 |
Move the C++11 support macros to a central place. |
3 |
This is a workaround for the FreeBSD 9.x series: in Qt 4.8.7, C++11 features |
6 |
|
4 |
are detected by checking if the compiler supports them. However, initializer |
7 |
The main objective of this commit is to make C++11 support work with |
5 |
lists support also depends on the C++ standard library. 9.x's libstdc++ from |
8 |
clang: so far, the Q_COMPILER_* definitions related to C++11 were |
6 |
base (GCC 4.2) does not, so ports with e.g. USES=compiler:c++0x or |
9 |
enabled based on __GNUC__ and __GNUC_MINOR__; while clang does define |
7 |
compiler:c++11-lang would break: they build with clang and base's libstdc++, so |
10 |
those two, __GNUC_MINOR__ is hardcoded at "2" and thus none of the |
8 |
Qt considers the support is there (including the C++ header) while this is not |
11 |
macros end up being defined. |
9 |
the case. |
12 |
|
|
|
13 |
We now make qglobal.h more similar to how qtbase's qcompilerdetection.h |
14 |
works by separating the detection of the C++11 features supported by a |
15 |
compiler from the detection of the compilers themselves. |
16 |
|
17 |
It is important to note the list of macros has not changed, the macros |
18 |
have only been moved. |
19 |
|
20 |
This commit either follows the spirit of or is a cherry-pick of the |
21 |
following qtbase ones: |
22 |
- 4131c323a36ee8680a3b4d66a2a03a00544751c2 (Update the C++11 support |
23 |
macros) |
24 |
- 8dd66f42e834320c4ba0a6f2e45855d591b3b6e7 (Avoid undefined macro |
25 |
warning for __GXX_EXPERIMENTAL_CXX0X__) |
26 |
- fe5d5fdaf1d9b7d108727d290e24a6b0f00139c6 (clang: Use __has_feature() |
27 |
to detect C++11 features) |
28 |
- 0ec953c93688ec0de74cda43b91f66f4cf879e5f (Remove extra Q_COMPILER_xxx |
29 |
defines from the MSVC section) |
30 |
- 163dcf2b71f34a12137f200e4af5640e42e5f5e2 (Fix build with older Clang |
31 |
versions without __has_extension) |
32 |
- 53262b9b5b9cb536916f6d6e086a944cb17bb8d8 (Only define the MSVC C++11 |
33 |
feature macros in C++) |
34 |
|
35 |
Change-Id: I2ca35af1a23260a9373943f97a8a72db3fc670e4 |
36 |
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> |
37 |
|
10 |
|
38 |
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h |
11 |
Work around the problem by only enabling Q_COMPILER_INITIALIZER_LISTS if libc++ |
39 |
index 158ef78..4f1384b 100644 |
12 |
is being used. Detecting libstdc++'s version is too cumbersome (we would at |
|
|
13 |
least need to include a non-lightweight header such as cstdio to have access to |
14 |
__GLIBCXX__) and not worth the effort. |
40 |
--- src/corelib/global/qglobal.h |
15 |
--- src/corelib/global/qglobal.h |
41 |
+++ src/corelib/global/qglobal.h |
16 |
+++ src/corelib/global/qglobal.h |
42 |
@@ -463,17 +463,6 @@ namespace QT_NAMESPACE {} |
17 |
@@ -854,7 +855,16 @@ namespace QT_NAMESPACE {} |
43 |
# undef QT_HAVE_3DNOW |
18 |
# define Q_COMPILER_DEFAULT_DELETE_MEMBERS |
44 |
# endif |
|
|
45 |
|
46 |
-#if defined(Q_CC_MSVC) && _MSC_VER >= 1600 |
47 |
-# define Q_COMPILER_RVALUE_REFS |
48 |
-# define Q_COMPILER_AUTO_FUNCTION |
49 |
-# define Q_COMPILER_AUTO_TYPE |
50 |
-# define Q_COMPILER_LAMBDA |
51 |
-# define Q_COMPILER_DECLTYPE |
52 |
-// MSCV has std::initilizer_list, but do not support the braces initialization |
53 |
-//# define Q_COMPILER_INITIALIZER_LISTS |
54 |
-# endif |
55 |
- |
56 |
- |
57 |
#elif defined(__BORLANDC__) || defined(__TURBOC__) |
58 |
# define Q_CC_BOR |
59 |
# define Q_INLINE_TEMPLATE |
60 |
@@ -505,6 +494,7 @@ namespace QT_NAMESPACE {} |
61 |
/* work-around for missing compiler intrinsics */ |
62 |
# define __is_empty(X) false |
63 |
# define __is_pod(X) false |
64 |
+ |
65 |
#elif defined(__GNUC__) |
66 |
# define Q_CC_GNU |
67 |
# define Q_C_CALLBACKS |
68 |
@@ -518,6 +508,10 @@ namespace QT_NAMESPACE {} |
69 |
# if defined(__clang__) |
70 |
/* Clang also masquerades as GCC 4.2.1 */ |
71 |
# define Q_CC_CLANG |
72 |
+# if !defined(__has_extension) |
73 |
+ /* Compatibility with older Clang versions */ |
74 |
+# define __has_extension __has_feature |
75 |
+# endif |
76 |
# endif |
77 |
# ifdef __APPLE__ |
78 |
# define Q_NO_DEPRECATED_CONSTRUCTORS |
79 |
@@ -558,33 +552,6 @@ namespace QT_NAMESPACE {} |
80 |
# define QT_NO_ARM_EABI |
81 |
# endif |
19 |
# endif |
82 |
# endif |
20 |
# if __has_feature(cxx_generalized_initializers) |
83 |
-# if defined(__GXX_EXPERIMENTAL_CXX0X__) |
|
|
84 |
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 |
85 |
- /* C++0x features supported in GCC 4.3: */ |
86 |
-# define Q_COMPILER_RVALUE_REFS |
87 |
-# define Q_COMPILER_DECLTYPE |
88 |
-# endif |
89 |
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 |
90 |
- /* C++0x features supported in GCC 4.4: */ |
91 |
-# define Q_COMPILER_VARIADIC_TEMPLATES |
92 |
-# define Q_COMPILER_AUTO_FUNCTION |
93 |
-# define Q_COMPILER_AUTO_TYPE |
94 |
-# define Q_COMPILER_EXTERN_TEMPLATES |
95 |
-# define Q_COMPILER_DEFAULT_DELETE_MEMBERS |
96 |
-# define Q_COMPILER_CLASS_ENUM |
97 |
-# define Q_COMPILER_INITIALIZER_LISTS |
21 |
-# define Q_COMPILER_INITIALIZER_LISTS |
98 |
-# endif |
|
|
99 |
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 |
100 |
- /* C++0x features supported in GCC 4.5: */ |
101 |
-# define Q_COMPILER_LAMBDA |
102 |
-# define Q_COMPILER_UNICODE_STRINGS |
103 |
-# endif |
104 |
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 |
105 |
- /* C++0x features supported in GCC 4.6: */ |
106 |
-# define Q_COMPILER_CONSTEXPR |
107 |
-# endif |
108 |
- |
109 |
-# endif |
110 |
|
111 |
/* IBM compiler versions are a bit messy. There are actually two products: |
112 |
the C product, and the C++ product. The C++ compiler is always packaged |
113 |
@@ -829,12 +796,33 @@ namespace QT_NAMESPACE {} |
114 |
# error "Qt has not been tested with this compiler - talk to qt-bugs@trolltech.com" |
115 |
#endif |
116 |
|
117 |
+/* |
22 |
+/* |
118 |
+ * C++11 support |
23 |
+ * Workaround for FreeBSD 9.x, where we can end up building a port with clang |
119 |
+ * |
24 |
+ * and base's libstdc++ from GCC 4.2 (which does not support initializer |
120 |
+ * Paper Macro SD-6 macro |
25 |
+ * lists). Since detecting libstdc++'s version is not trivial, only enable the |
121 |
+ * N2541 Q_COMPILER_AUTO_FUNCTION |
26 |
+ * macro with libc++. |
122 |
+ * N1984 N2546 Q_COMPILER_AUTO_TYPE |
|
|
123 |
+ * N2437 Q_COMPILER_CLASS_ENUM |
124 |
+ * N2235 Q_COMPILER_CONSTEXPR __cpp_constexpr = 200704 |
125 |
+ * N2343 N3276 Q_COMPILER_DECLTYPE __cpp_decltype = 200707 |
126 |
+ * N2346 Q_COMPILER_DEFAULT_DELETE_MEMBERS |
127 |
+ * N1987 Q_COMPILER_EXTERN_TEMPLATES |
128 |
+ * N2672 Q_COMPILER_INITIALIZER_LISTS |
129 |
+ * N2658 N2927 Q_COMPILER_LAMBDA __cpp_lambdas = 200907 |
130 |
+ * N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS __cpp_rvalue_references = 200610 |
131 |
+ * N2442 Q_COMPILER_UNICODE_STRINGS __cpp_unicode_literals = 200710 |
132 |
+ * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES __cpp_variadic_templates = 200704 |
133 |
+ * |
134 |
+ * For any future version of the C++ standard, we use only the SD-6 macro. |
135 |
+ * For full listing, see |
136 |
+ * http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations |
137 |
+ */ |
27 |
+ */ |
138 |
|
28 |
+# include <ciso646> |
139 |
#ifdef Q_CC_INTEL |
29 |
+# if defined(_LIBCPP_VER) |
140 |
# if __INTEL_COMPILER < 1200 |
30 |
+# define Q_COMPILER_INITIALIZER_LISTS |
141 |
# define Q_NO_TEMPLATE_FRIENDS |
31 |
+# endif |
142 |
# endif |
32 |
# endif |
143 |
-# if defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__) |
33 |
# if __has_feature(cxx_lambdas) |
144 |
+# if __cplusplus >= 201103L |
34 |
# define Q_COMPILER_LAMBDA |
145 |
# if __INTEL_COMPILER >= 1100 |
|
|
146 |
# define Q_COMPILER_RVALUE_REFS |
147 |
# define Q_COMPILER_EXTERN_TEMPLATES |
148 |
@@ -849,6 +837,91 @@ namespace QT_NAMESPACE {} |
149 |
# endif |
150 |
#endif |
151 |
|
152 |
+#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) |
153 |
+# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) |
154 |
+ /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */ |
155 |
+# if __has_feature(cxx_auto_type) |
156 |
+# define Q_COMPILER_AUTO_FUNCTION |
157 |
+# define Q_COMPILER_AUTO_TYPE |
158 |
+# endif |
159 |
+# if __has_feature(cxx_constexpr) |
160 |
+# define Q_COMPILER_CONSTEXPR |
161 |
+# endif |
162 |
+# if __has_feature(cxx_decltype) /* && __has_feature(cxx_decltype_incomplete_return_types) */ |
163 |
+# define Q_COMPILER_DECLTYPE |
164 |
+# endif |
165 |
+# if __has_feature(cxx_defaulted_functions) && __has_feature(cxx_deleted_functions) |
166 |
+# define Q_COMPILER_DEFAULT_DELETE_MEMBERS |
167 |
+# endif |
168 |
+# if __has_feature(cxx_generalized_initializers) |
169 |
+# define Q_COMPILER_INITIALIZER_LISTS |
170 |
+# endif |
171 |
+# if __has_feature(cxx_lambdas) |
172 |
+# define Q_COMPILER_LAMBDA |
173 |
+# endif |
174 |
+# if __has_feature(cxx_rvalue_references) |
175 |
+# define Q_COMPILER_RVALUE_REFS |
176 |
+# endif |
177 |
+# if __has_feature(cxx_strong_enums) |
178 |
+# define Q_COMPILER_CLASS_ENUM |
179 |
+# endif |
180 |
+# if __has_feature(cxx_unicode_literals) |
181 |
+# define Q_COMPILER_UNICODE_STRINGS |
182 |
+# endif |
183 |
+# if __has_feature(cxx_variadic_templates) |
184 |
+# define Q_COMPILER_VARIADIC_TEMPLATES |
185 |
+# endif |
186 |
+ /* Features that have no __has_feature() check */ |
187 |
+# if ((__clang_major__ * 100) + __clang_minor__) >= 209 /* since clang 2.9 */ |
188 |
+# define Q_COMPILER_EXTERN_TEMPLATES |
189 |
+# endif |
190 |
+# endif |
191 |
+#endif |
192 |
+ |
193 |
+#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) |
194 |
+# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
195 |
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403 |
196 |
+ /* C++0x features supported in GCC 4.3: */ |
197 |
+# define Q_COMPILER_RVALUE_REFS |
198 |
+# define Q_COMPILER_DECLTYPE |
199 |
+# endif |
200 |
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 |
201 |
+ /* C++0x features supported in GCC 4.4: */ |
202 |
+# define Q_COMPILER_VARIADIC_TEMPLATES |
203 |
+# define Q_COMPILER_AUTO_FUNCTION |
204 |
+# define Q_COMPILER_AUTO_TYPE |
205 |
+# define Q_COMPILER_EXTERN_TEMPLATES |
206 |
+# define Q_COMPILER_DEFAULT_DELETE_MEMBERS |
207 |
+# define Q_COMPILER_CLASS_ENUM |
208 |
+# define Q_COMPILER_INITIALIZER_LISTS |
209 |
+# endif |
210 |
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 |
211 |
+ /* C++0x features supported in GCC 4.5: */ |
212 |
+# define Q_COMPILER_LAMBDA |
213 |
+# define Q_COMPILER_UNICODE_STRINGS |
214 |
+# endif |
215 |
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 |
216 |
+ /* C++0x features supported in GCC 4.6: */ |
217 |
+# define Q_COMPILER_CONSTEXPR |
218 |
+# endif |
219 |
+# endif |
220 |
+#endif |
221 |
+ |
222 |
+#if defined(Q_CC_MSVC) && !defined(Q_CC_INTEL) |
223 |
+# if defined(__cplusplus) |
224 |
+# if _MSC_VER >= 1600 |
225 |
+ /* C++11 features supported in VC10 = VC2010: */ |
226 |
+# define Q_COMPILER_AUTO_FUNCTION |
227 |
+# define Q_COMPILER_AUTO_TYPE |
228 |
+# define Q_COMPILER_DECLTYPE |
229 |
+# define Q_COMPILER_LAMBDA |
230 |
+# define Q_COMPILER_RVALUE_REFS |
231 |
+// MSVC's library has std::initializer_list, but the compiler does not support the braces initialization |
232 |
+//# define Q_COMPILER_INITIALIZER_LISTS |
233 |
+# endif |
234 |
+# endif |
235 |
+#endif |
236 |
+ |
237 |
#ifndef Q_PACKED |
238 |
# define Q_PACKED |
239 |
# undef Q_NO_PACKED_REFERENCE |