| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // Copyright (C) 2016 Intel Corporation. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | #if 0 |
| 6 | #pragma qt_class(QtCompilerDetection) |
| 7 | #pragma qt_sync_skip_header_check |
| 8 | #pragma qt_sync_stop_processing |
| 9 | #endif |
| 10 | |
| 11 | #ifndef QCOMPILERDETECTION_H |
| 12 | #define QCOMPILERDETECTION_H |
| 13 | |
| 14 | #include <QtCore/qprocessordetection.h> |
| 15 | #include <QtCore/qsystemdetection.h> |
| 16 | #include <QtCore/qtconfiginclude.h> |
| 17 | |
| 18 | /* |
| 19 | The compiler, must be one of: (Q_CC_x) |
| 20 | |
| 21 | COVERITY - Coverity cov-scan |
| 22 | SYM - Digital Mars C/C++ (used to be Symantec C++) |
| 23 | MSVC - Microsoft Visual C/C++, Intel C++ for Windows |
| 24 | BOR - Borland/Turbo C++ |
| 25 | WAT - Watcom C++ |
| 26 | GNU - GNU C++ |
| 27 | COMEAU - Comeau C++ |
| 28 | EDG - Edison Design Group C++ |
| 29 | OC - CenterLine C++ |
| 30 | SUN - Forte Developer, or Sun Studio C++ |
| 31 | MIPS - MIPSpro C++ |
| 32 | DEC - DEC C++ |
| 33 | HPACC - HP aC++ |
| 34 | USLC - SCO OUDK and UDK |
| 35 | CDS - Reliant C++ |
| 36 | KAI - KAI C++ |
| 37 | INTEL - Intel C++ for Linux, Intel C++ for Windows |
| 38 | HIGHC - MetaWare High C/C++ |
| 39 | PGI - Portland Group C++ |
| 40 | GHS - Green Hills Optimizing C++ Compilers |
| 41 | RVCT - ARM Realview Compiler Suite |
| 42 | CLANG - C++ front-end for the LLVM compiler |
| 43 | |
| 44 | |
| 45 | Should be sorted most to least authoritative. |
| 46 | */ |
| 47 | |
| 48 | #if defined(__COVERITY__) |
| 49 | # define Q_CC_COVERITY |
| 50 | # define Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE |
| 51 | #endif |
| 52 | |
| 53 | /* Symantec C++ is now Digital Mars */ |
| 54 | #if defined(__DMC__) || defined(__SC__) |
| 55 | # define Q_CC_SYM |
| 56 | /* "explicit" semantics implemented in 8.1e but keyword recognized since 7.5 */ |
| 57 | # if defined(__SC__) && __SC__ < 0x750 |
| 58 | # error "Compiler not supported" |
| 59 | # endif |
| 60 | |
| 61 | #elif defined(_MSC_VER) |
| 62 | # define Q_CC_MSVC (_MSC_VER) |
| 63 | # define Q_CC_MSVC_NET |
| 64 | # define Q_CC_MSVC_ONLY Q_CC_MSVC |
| 65 | # ifdef __clang__ |
| 66 | # undef Q_CC_MSVC_ONLY |
| 67 | # define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__) |
| 68 | # define Q_CC_CLANG_ONLY Q_CC_CLANG |
| 69 | # endif |
| 70 | # define Q_OUTOFLINE_TEMPLATE inline |
| 71 | # define Q_COMPILER_MANGLES_RETURN_TYPE |
| 72 | # define Q_COMPILER_MANGLES_ACCESS_SPECIFIER |
| 73 | # define Q_FUNC_INFO __FUNCSIG__ |
| 74 | # define Q_ASSUME_IMPL(expr) __assume(expr) |
| 75 | # define Q_UNREACHABLE_IMPL() __assume(0) |
| 76 | # define Q_DECL_EXPORT __declspec(dllexport) |
| 77 | # define Q_DECL_IMPORT __declspec(dllimport) |
| 78 | # if _MSC_VER < 1938 // stdext is deprecated since VS 2022 17.8 |
| 79 | # define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) stdext::make_checked_array_iterator(x, size_t(N)) // Since _MSC_VER >= 1500 |
| 80 | # endif |
| 81 | # ifdef Q_CC_MSVC_ONLY |
| 82 | # define Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE |
| 83 | # endif |
| 84 | |
| 85 | #elif defined(__BORLANDC__) || defined(__TURBOC__) |
| 86 | # define Q_CC_BOR |
| 87 | # define Q_INLINE_TEMPLATE |
| 88 | # if __BORLANDC__ < 0x502 |
| 89 | # error "Compiler not supported" |
| 90 | # endif |
| 91 | |
| 92 | #elif defined(__WATCOMC__) |
| 93 | # define Q_CC_WAT |
| 94 | |
| 95 | /* ARM Realview Compiler Suite |
| 96 | RVCT compiler also defines __EDG__ and __GNUC__ (if --gnu flag is given), |
| 97 | so check for it before that */ |
| 98 | #elif defined(__ARMCC__) || defined(__CC_ARM) |
| 99 | # define Q_CC_RVCT |
| 100 | /* work-around for missing compiler intrinsics */ |
| 101 | # define __is_empty(X) false |
| 102 | # define __is_pod(X) false |
| 103 | # define Q_DECL_DEPRECATED __attribute__ ((__deprecated__)) |
| 104 | # ifdef Q_OS_LINUX |
| 105 | # define Q_DECL_EXPORT __attribute__((visibility("default"))) |
| 106 | # define Q_DECL_IMPORT __attribute__((visibility("default"))) |
| 107 | # define Q_DECL_HIDDEN __attribute__((visibility("hidden"))) |
| 108 | # else |
| 109 | # define Q_DECL_EXPORT __declspec(dllexport) |
| 110 | # define Q_DECL_IMPORT __declspec(dllimport) |
| 111 | # endif |
| 112 | |
| 113 | #elif defined(__GNUC__) |
| 114 | # define Q_CC_GNU (__GNUC__ * 100 + __GNUC_MINOR__) |
| 115 | # if defined(__MINGW32__) |
| 116 | # define Q_CC_MINGW |
| 117 | # endif |
| 118 | # if defined(__clang__) |
| 119 | /* Clang also masquerades as GCC */ |
| 120 | # if defined(__apple_build_version__) |
| 121 | // The Clang version reported by Apple Clang in __clang_major__ |
| 122 | // and __clang_minor__ does _not_ reflect the actual upstream |
| 123 | // version of the compiler. To allow consumers to use a single |
| 124 | // define to verify the Clang version we hard-code the versions |
| 125 | // based on the best available info we have about the actual |
| 126 | // version: http://en.wikipedia.org/wiki/Xcode#Toolchain_Versions |
| 127 | # if __apple_build_version__ >= 17000013 // Xcode 16.3 |
| 128 | # define Q_CC_CLANG 1914 |
| 129 | # elif __apple_build_version__ >= 16000026 // Xcode 16.0 |
| 130 | # define Q_CC_CLANG 1706 |
| 131 | # elif __apple_build_version__ >= 15000040 // Xcode 15.0 |
| 132 | # define Q_CC_CLANG 1600 |
| 133 | # elif __apple_build_version__ >= 14030022 // Xcode 14.3 |
| 134 | # define Q_CC_CLANG 1500 |
| 135 | # elif __apple_build_version__ >= 14000029 // Xcode 14.0 |
| 136 | # define Q_CC_CLANG 1400 |
| 137 | # elif __apple_build_version__ >= 13160021 // Xcode 13.3 |
| 138 | # define Q_CC_CLANG 1300 |
| 139 | # elif __apple_build_version__ >= 13000029 // Xcode 13.0 |
| 140 | # define Q_CC_CLANG 1200 |
| 141 | # elif __apple_build_version__ >= 12050022 // Xcode 12.5 |
| 142 | # define Q_CC_CLANG 1110 |
| 143 | # elif __apple_build_version__ >= 12000032 // Xcode 12.0 |
| 144 | # define Q_CC_CLANG 1000 |
| 145 | # elif __apple_build_version__ >= 11030032 // Xcode 11.4 |
| 146 | # define Q_CC_CLANG 900 |
| 147 | # elif __apple_build_version__ >= 11000033 // Xcode 11.0 |
| 148 | # define Q_CC_CLANG 800 |
| 149 | # else |
| 150 | # error "Unsupported Apple Clang version" |
| 151 | # endif |
| 152 | # else |
| 153 | // Non-Apple Clang, so we trust the versions reported |
| 154 | # define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__) |
| 155 | # endif |
| 156 | # define Q_CC_CLANG_ONLY Q_CC_CLANG |
| 157 | # if __has_builtin(__builtin_assume) |
| 158 | # define Q_ASSUME_IMPL(expr) __builtin_assume(expr) |
| 159 | # else |
| 160 | # define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() |
| 161 | # endif |
| 162 | # define Q_UNREACHABLE_IMPL() __builtin_unreachable() |
| 163 | # if !defined(__has_extension) |
| 164 | # /* Compatibility with older Clang versions */ |
| 165 | # define __has_extension __has_feature |
| 166 | # endif |
| 167 | # if defined(__APPLE__) |
| 168 | /* Apple/clang specific features */ |
| 169 | # define Q_DECL_CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) |
| 170 | # ifdef __OBJC__ |
| 171 | # define Q_DECL_NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased)) |
| 172 | # endif |
| 173 | # endif |
| 174 | # ifdef __EMSCRIPTEN__ |
| 175 | # define Q_CC_EMSCRIPTEN |
| 176 | # endif |
| 177 | # else |
| 178 | /* Plain GCC */ |
| 179 | # define Q_CC_GNU_ONLY Q_CC_GNU |
| 180 | # if Q_CC_GNU >= 405 |
| 181 | # define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() |
| 182 | # define Q_UNREACHABLE_IMPL() __builtin_unreachable() |
| 183 | # define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text))) |
| 184 | # endif |
| 185 | # endif |
| 186 | |
| 187 | # ifdef Q_OS_WIN |
| 188 | # define Q_DECL_EXPORT __declspec(dllexport) |
| 189 | # define Q_DECL_IMPORT __declspec(dllimport) |
| 190 | # else |
| 191 | # define Q_DECL_EXPORT_OVERRIDABLE __attribute__((visibility("default"), weak)) |
| 192 | # ifdef QT_USE_PROTECTED_VISIBILITY |
| 193 | # define Q_DECL_EXPORT __attribute__((visibility("protected"))) |
| 194 | # else |
| 195 | # define Q_DECL_EXPORT __attribute__((visibility("default"))) |
| 196 | # endif |
| 197 | # define Q_DECL_IMPORT __attribute__((visibility("default"))) |
| 198 | # define Q_DECL_HIDDEN __attribute__((visibility("hidden"))) |
| 199 | # endif |
| 200 | |
| 201 | # define Q_FUNC_INFO __PRETTY_FUNCTION__ |
| 202 | # define Q_TYPEOF(expr) __typeof__(expr) |
| 203 | # define Q_DECL_DEPRECATED __attribute__ ((__deprecated__)) |
| 204 | # define Q_DECL_UNUSED __attribute__((__unused__)) |
| 205 | # define Q_LIKELY(expr) __builtin_expect(!!(expr), true) |
| 206 | # define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false) |
| 207 | # define Q_NORETURN __attribute__((__noreturn__)) |
| 208 | # define Q_REQUIRED_RESULT __attribute__ ((__warn_unused_result__)) |
| 209 | # define Q_DECL_PURE_FUNCTION __attribute__((pure)) |
| 210 | # define Q_DECL_CONST_FUNCTION __attribute__((const)) |
| 211 | # define Q_DECL_COLD_FUNCTION __attribute__((cold)) |
| 212 | # define Q_PACKED __attribute__ ((__packed__)) |
| 213 | # ifndef __ARM_EABI__ |
| 214 | # define QT_NO_ARM_EABI |
| 215 | # endif |
| 216 | # if Q_CC_GNU >= 403 && !defined(Q_CC_CLANG) |
| 217 | # define Q_ALLOC_SIZE(x) __attribute__((alloc_size(x))) |
| 218 | # endif |
| 219 | |
| 220 | /* IBM compiler versions are a bit messy. There are actually two products: |
| 221 | the C product, and the C++ product. The C++ compiler is always packaged |
| 222 | with the latest version of the C compiler. Version numbers do not always |
| 223 | match. This little table (I'm not sure it's accurate) should be helpful: |
| 224 | |
| 225 | C++ product C product |
| 226 | |
| 227 | C Set 3.1 C Compiler 3.0 |
| 228 | ... ... |
| 229 | C++ Compiler 3.6.6 C Compiler 4.3 |
| 230 | ... ... |
| 231 | Visual Age C++ 4.0 ... |
| 232 | ... ... |
| 233 | Visual Age C++ 5.0 C Compiler 5.0 |
| 234 | ... ... |
| 235 | Visual Age C++ 6.0 C Compiler 6.0 |
| 236 | |
| 237 | Now: |
| 238 | __xlC__ is the version of the C compiler in hexadecimal notation |
| 239 | is only an approximation of the C++ compiler version |
| 240 | __IBMCPP__ is the version of the C++ compiler in decimal notation |
| 241 | but it is not defined on older compilers like C Set 3.1 */ |
| 242 | #elif defined(__xlC__) |
| 243 | # define Q_CC_XLC |
| 244 | # if __xlC__ < 0x400 |
| 245 | # error "Compiler not supported" |
| 246 | # elif __xlC__ >= 0x0600 |
| 247 | # define Q_TYPEOF(expr) __typeof__(expr) |
| 248 | # define Q_PACKED __attribute__((__packed__)) |
| 249 | # endif |
| 250 | |
| 251 | /* Older versions of DEC C++ do not define __EDG__ or __EDG - observed |
| 252 | on DEC C++ V5.5-004. New versions do define __EDG__ - observed on |
| 253 | Compaq C++ V6.3-002. |
| 254 | This compiler is different enough from other EDG compilers to handle |
| 255 | it separately anyway. */ |
| 256 | #elif defined(__DECCXX) || defined(__DECC) |
| 257 | # define Q_CC_DEC |
| 258 | /* Compaq C++ V6 compilers are EDG-based but I'm not sure about older |
| 259 | DEC C++ V5 compilers. */ |
| 260 | # if defined(__EDG__) |
| 261 | # define Q_CC_EDG |
| 262 | # endif |
| 263 | /* Compaq has disabled EDG's _BOOL macro and uses _BOOL_EXISTS instead |
| 264 | - observed on Compaq C++ V6.3-002. |
| 265 | In any case versions prior to Compaq C++ V6.0-005 do not have bool. */ |
| 266 | # if !defined(_BOOL_EXISTS) |
| 267 | # error "Compiler not supported" |
| 268 | # endif |
| 269 | /* Spurious (?) error messages observed on Compaq C++ V6.5-014. */ |
| 270 | /* Apply to all versions prior to Compaq C++ V6.0-000 - observed on |
| 271 | DEC C++ V5.5-004. */ |
| 272 | # if __DECCXX_VER < 60060000 |
| 273 | # define Q_BROKEN_TEMPLATE_SPECIALIZATION |
| 274 | # endif |
| 275 | /* avoid undefined symbol problems with out-of-line template members */ |
| 276 | # define Q_OUTOFLINE_TEMPLATE inline |
| 277 | |
| 278 | /* The Portland Group C++ compiler is based on EDG and does define __EDG__ |
| 279 | but the C compiler does not */ |
| 280 | #elif defined(__PGI) |
| 281 | # define Q_CC_PGI |
| 282 | # if defined(__EDG__) |
| 283 | # define Q_CC_EDG |
| 284 | # endif |
| 285 | |
| 286 | /* Compilers with EDG front end are similar. To detect them we test: |
| 287 | __EDG documented by SGI, observed on MIPSpro 7.3.1.1 and KAI C++ 4.0b |
| 288 | __EDG__ documented in EDG online docs, observed on Compaq C++ V6.3-002 |
| 289 | and PGI C++ 5.2-4 */ |
| 290 | #elif !defined(Q_OS_HPUX) && (defined(__EDG) || defined(__EDG__)) |
| 291 | # define Q_CC_EDG |
| 292 | /* From the EDG documentation (does not seem to apply to Compaq C++ or GHS C): |
| 293 | _BOOL |
| 294 | Defined in C++ mode when bool is a keyword. The name of this |
| 295 | predefined macro is specified by a configuration flag. _BOOL |
| 296 | is the default. |
| 297 | __BOOL_DEFINED |
| 298 | Defined in Microsoft C++ mode when bool is a keyword. */ |
| 299 | # if !defined(_BOOL) && !defined(__BOOL_DEFINED) && !defined(__ghs) |
| 300 | # error "Compiler not supported" |
| 301 | # endif |
| 302 | |
| 303 | /* The Comeau compiler is based on EDG and does define __EDG__ */ |
| 304 | # if defined(__COMO__) |
| 305 | # define Q_CC_COMEAU |
| 306 | |
| 307 | /* The `using' keyword was introduced to avoid KAI C++ warnings |
| 308 | but it's now causing KAI C++ errors instead. The standard is |
| 309 | unclear about the use of this keyword, and in practice every |
| 310 | compiler is using its own set of rules. Forget it. */ |
| 311 | # elif defined(__KCC) |
| 312 | # define Q_CC_KAI |
| 313 | |
| 314 | /* Uses CFront, make sure to read the manual how to tweak templates. */ |
| 315 | # elif defined(__ghs) |
| 316 | # define Q_CC_GHS |
| 317 | # define Q_DECL_DEPRECATED __attribute__ ((__deprecated__)) |
| 318 | # define Q_PACKED __attribute__ ((__packed__)) |
| 319 | # define Q_FUNC_INFO __PRETTY_FUNCTION__ |
| 320 | # define Q_TYPEOF(expr) __typeof__(expr) |
| 321 | # define Q_UNREACHABLE_IMPL() |
| 322 | # if defined(__cplusplus) |
| 323 | # define Q_COMPILER_AUTO_TYPE |
| 324 | # define Q_COMPILER_STATIC_ASSERT |
| 325 | # define Q_COMPILER_RANGE_FOR |
| 326 | # if __GHS_VERSION_NUMBER >= 201505 |
| 327 | # define Q_COMPILER_ALIGNAS |
| 328 | # define Q_COMPILER_ALIGNOF |
| 329 | # define Q_COMPILER_ATOMICS |
| 330 | # define Q_COMPILER_ATTRIBUTES |
| 331 | # define Q_COMPILER_AUTO_FUNCTION |
| 332 | # define Q_COMPILER_CLASS_ENUM |
| 333 | # define Q_COMPILER_DECLTYPE |
| 334 | # define Q_COMPILER_DEFAULT_MEMBERS |
| 335 | # define Q_COMPILER_DELETE_MEMBERS |
| 336 | # define Q_COMPILER_DELEGATING_CONSTRUCTORS |
| 337 | # define Q_COMPILER_EXPLICIT_CONVERSIONS |
| 338 | # define Q_COMPILER_EXPLICIT_OVERRIDES |
| 339 | # define Q_COMPILER_EXTERN_TEMPLATES |
| 340 | # define Q_COMPILER_INHERITING_CONSTRUCTORS |
| 341 | # define Q_COMPILER_INITIALIZER_LISTS |
| 342 | # define Q_COMPILER_LAMBDA |
| 343 | # define Q_COMPILER_NONSTATIC_MEMBER_INIT |
| 344 | # define Q_COMPILER_NOEXCEPT |
| 345 | # define Q_COMPILER_NULLPTR |
| 346 | # define Q_COMPILER_RANGE_FOR |
| 347 | # define Q_COMPILER_RAW_STRINGS |
| 348 | # define Q_COMPILER_REF_QUALIFIERS |
| 349 | # define Q_COMPILER_RVALUE_REFS |
| 350 | # define Q_COMPILER_STATIC_ASSERT |
| 351 | # define Q_COMPILER_TEMPLATE_ALIAS |
| 352 | # define Q_COMPILER_THREAD_LOCAL |
| 353 | # define Q_COMPILER_UDL |
| 354 | # define Q_COMPILER_UNICODE_STRINGS |
| 355 | # define Q_COMPILER_UNIFORM_INIT |
| 356 | # define Q_COMPILER_UNRESTRICTED_UNIONS |
| 357 | # define Q_COMPILER_VARIADIC_MACROS |
| 358 | # define Q_COMPILER_VARIADIC_TEMPLATES |
| 359 | # endif |
| 360 | # endif //__cplusplus |
| 361 | |
| 362 | # elif defined(__DCC__) |
| 363 | # define Q_CC_DIAB |
| 364 | # if !defined(__bool) |
| 365 | # error "Compiler not supported" |
| 366 | # endif |
| 367 | |
| 368 | /* The UnixWare 7 UDK compiler is based on EDG and does define __EDG__ */ |
| 369 | # elif defined(__USLC__) && defined(__SCO_VERSION__) |
| 370 | # define Q_CC_USLC |
| 371 | /* The latest UDK 7.1.1b does not need this, but previous versions do */ |
| 372 | # if !defined(__SCO_VERSION__) || (__SCO_VERSION__ < 302200010) |
| 373 | # define Q_OUTOFLINE_TEMPLATE inline |
| 374 | # endif |
| 375 | |
| 376 | /* Never tested! */ |
| 377 | # elif defined(CENTERLINE_CLPP) || defined(OBJECTCENTER) |
| 378 | # define Q_CC_OC |
| 379 | |
| 380 | /* CDS++ defines __EDG__ although this is not documented in the Reliant |
| 381 | documentation. It also follows conventions like _BOOL and this documented */ |
| 382 | # elif defined(sinix) |
| 383 | # define Q_CC_CDS |
| 384 | # endif |
| 385 | |
| 386 | /* VxWorks' DIAB toolchain has an additional EDG type C++ compiler |
| 387 | (see __DCC__ above). This one is for C mode files (__EDG is not defined) */ |
| 388 | #elif defined(_DIAB_TOOL) |
| 389 | # define Q_CC_DIAB |
| 390 | # define Q_FUNC_INFO __PRETTY_FUNCTION__ |
| 391 | |
| 392 | /* Never tested! */ |
| 393 | #elif defined(__HIGHC__) |
| 394 | # define Q_CC_HIGHC |
| 395 | |
| 396 | #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) |
| 397 | # define Q_CC_SUN |
| 398 | # define Q_COMPILER_MANGLES_RETURN_TYPE |
| 399 | /* 5.0 compiler or better |
| 400 | 'bool' is enabled by default but can be disabled using -features=nobool |
| 401 | in which case _BOOL is not defined |
| 402 | this is the default in 4.2 compatibility mode triggered by -compat=4 */ |
| 403 | # if __SUNPRO_CC >= 0x500 |
| 404 | # define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS |
| 405 | /* see http://developers.sun.com/sunstudio/support/Ccompare.html */ |
| 406 | # if __SUNPRO_CC >= 0x590 |
| 407 | # define Q_TYPEOF(expr) __typeof__(expr) |
| 408 | # endif |
| 409 | # if __SUNPRO_CC >= 0x550 |
| 410 | # define Q_DECL_EXPORT __global |
| 411 | # endif |
| 412 | # if !defined(_BOOL) |
| 413 | # error "Compiler not supported" |
| 414 | # endif |
| 415 | /* 4.2 compiler or older */ |
| 416 | # else |
| 417 | # error "Compiler not supported" |
| 418 | # endif |
| 419 | |
| 420 | /* CDS++ does not seem to define __EDG__ or __EDG according to Reliant |
| 421 | documentation but nevertheless uses EDG conventions like _BOOL */ |
| 422 | #elif defined(sinix) |
| 423 | # define Q_CC_EDG |
| 424 | # define Q_CC_CDS |
| 425 | # if !defined(_BOOL) |
| 426 | # error "Compiler not supported" |
| 427 | # endif |
| 428 | # define Q_BROKEN_TEMPLATE_SPECIALIZATION |
| 429 | |
| 430 | #else |
| 431 | # error "Qt has not been tested with this compiler - see http://www.qt-project.org/" |
| 432 | #endif |
| 433 | |
| 434 | /* |
| 435 | * SG10's SD-6 feature detection and some useful extensions from Clang and GCC |
| 436 | * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations |
| 437 | * http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros |
| 438 | * Not using wrapper macros, per http://eel.is/c++draft/cpp.cond#7.sentence-2 |
| 439 | */ |
| 440 | #ifndef __has_builtin |
| 441 | # define __has_builtin(x) 0 |
| 442 | #endif |
| 443 | #ifndef __has_feature |
| 444 | # define __has_feature(x) 0 |
| 445 | #endif |
| 446 | #ifndef __has_attribute |
| 447 | # define __has_attribute(x) 0 |
| 448 | #endif |
| 449 | #ifndef __has_c_attribute |
| 450 | # define __has_c_attribute(x) 0 |
| 451 | #endif |
| 452 | #ifndef __has_cpp_attribute |
| 453 | # define __has_cpp_attribute(x) 0 |
| 454 | #endif |
| 455 | #ifndef __has_include |
| 456 | # define __has_include(x) 0 |
| 457 | #endif |
| 458 | #ifndef __has_include_next |
| 459 | # define __has_include_next(x) 0 |
| 460 | #endif |
| 461 | |
| 462 | /* |
| 463 | detecting ASAN can be helpful to disable slow tests |
| 464 | clang uses feature, gcc defines __SANITIZE_ADDRESS__ |
| 465 | unconditionally check both in case other compilers mirror |
| 466 | either of those options |
| 467 | */ |
| 468 | #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
| 469 | # define QT_ASAN_ENABLED |
| 470 | #endif |
| 471 | |
| 472 | /* |
| 473 | * C++11 support |
| 474 | * |
| 475 | * Paper Macro SD-6 macro |
| 476 | * N2341 Q_COMPILER_ALIGNAS |
| 477 | * N2341 Q_COMPILER_ALIGNOF |
| 478 | * N2427 Q_COMPILER_ATOMICS |
| 479 | * N2761 Q_COMPILER_ATTRIBUTES __cpp_attributes = 200809 |
| 480 | * N2541 Q_COMPILER_AUTO_FUNCTION |
| 481 | * N1984 N2546 Q_COMPILER_AUTO_TYPE |
| 482 | * N2437 Q_COMPILER_CLASS_ENUM |
| 483 | * N2235 Q_COMPILER_CONSTEXPR __cpp_constexpr = 200704 |
| 484 | * N2343 N3276 Q_COMPILER_DECLTYPE __cpp_decltype = 200707 |
| 485 | * N2346 Q_COMPILER_DEFAULT_MEMBERS |
| 486 | * N2346 Q_COMPILER_DELETE_MEMBERS |
| 487 | * N1986 Q_COMPILER_DELEGATING_CONSTRUCTORS |
| 488 | * N2437 Q_COMPILER_EXPLICIT_CONVERSIONS |
| 489 | * N3206 N3272 Q_COMPILER_EXPLICIT_OVERRIDES |
| 490 | * N1987 Q_COMPILER_EXTERN_TEMPLATES |
| 491 | * N2540 Q_COMPILER_INHERITING_CONSTRUCTORS |
| 492 | * N2672 Q_COMPILER_INITIALIZER_LISTS |
| 493 | * N2658 N2927 Q_COMPILER_LAMBDA __cpp_lambdas = 200907 |
| 494 | * N2756 Q_COMPILER_NONSTATIC_MEMBER_INIT |
| 495 | * N2855 N3050 Q_COMPILER_NOEXCEPT |
| 496 | * N2431 Q_COMPILER_NULLPTR |
| 497 | * N2930 Q_COMPILER_RANGE_FOR |
| 498 | * N2442 Q_COMPILER_RAW_STRINGS __cpp_raw_strings = 200710 |
| 499 | * N2439 Q_COMPILER_REF_QUALIFIERS |
| 500 | * N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS __cpp_rvalue_references = 200610 |
| 501 | * N1720 Q_COMPILER_STATIC_ASSERT __cpp_static_assert = 200410 |
| 502 | * N2258 Q_COMPILER_TEMPLATE_ALIAS |
| 503 | * N2659 Q_COMPILER_THREAD_LOCAL |
| 504 | * N2660 Q_COMPILER_THREADSAFE_STATICS |
| 505 | * N2765 Q_COMPILER_UDL __cpp_user_defined_literals = 200809 |
| 506 | * N2442 Q_COMPILER_UNICODE_STRINGS __cpp_unicode_literals = 200710 |
| 507 | * N2640 Q_COMPILER_UNIFORM_INIT |
| 508 | * N2544 Q_COMPILER_UNRESTRICTED_UNIONS |
| 509 | * N1653 Q_COMPILER_VARIADIC_MACROS |
| 510 | * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES __cpp_variadic_templates = 200704 |
| 511 | * |
| 512 | * |
| 513 | * For the C++ standards C++14 and C++17, we use only the SD-6 macro. |
| 514 | * |
| 515 | * For any future version of the C++ standard, we use only the C++20 feature test macro. |
| 516 | * For library features, we assume <version> is present (this header includes it). |
| 517 | * |
| 518 | * For a full listing of feature test macros, see |
| 519 | * https://en.cppreference.com/w/cpp/feature_test |
| 520 | * Exceptions: |
| 521 | * Q_DECL_CONSTEXPR_DTOR constexpr in C++20 for explicit destructors __cpp_constexpr >= 201907L |
| 522 | * Q_CONSTEXPR_DTOR constexpr in C++20 for variables __cpp_constexpr >= 201907L otherwise const |
| 523 | * Q_DECL_EQ_DELETE_X(message) = delete("reason"), __cpp_deleted_function >= 202403L |
| 524 | * |
| 525 | * C++ extensions: |
| 526 | * Q_COMPILER_RESTRICTED_VLA variable-length arrays, prior to __cpp_runtime_arrays |
| 527 | */ |
| 528 | |
| 529 | /* |
| 530 | * Now that we require C++17, we unconditionally expect threadsafe statics mandated since C++11 |
| 531 | */ |
| 532 | #define Q_COMPILER_THREADSAFE_STATICS |
| 533 | |
| 534 | #if defined(Q_CC_CLANG) |
| 535 | /* General C++ features */ |
| 536 | # define Q_COMPILER_RESTRICTED_VLA |
| 537 | # if __has_feature(attribute_deprecated_with_message) |
| 538 | # define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text))) |
| 539 | # endif |
| 540 | |
| 541 | // Clang supports binary literals in C, C++98 and C++11 modes |
| 542 | // It's been supported "since the dawn of time itself" (cf. commit 179883) |
| 543 | # if __has_extension(cxx_binary_literals) |
| 544 | # define Q_COMPILER_BINARY_LITERALS |
| 545 | # endif |
| 546 | |
| 547 | // Variadic macros are supported for gnu++98, c++11, c99 ... since 2.9 |
| 548 | # if Q_CC_CLANG >= 209 |
| 549 | # if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \ |
| 550 | || (defined(__cplusplus) && (__cplusplus >= 201103L)) \ |
| 551 | || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) |
| 552 | # define Q_COMPILER_VARIADIC_MACROS |
| 553 | # endif |
| 554 | # endif |
| 555 | |
| 556 | /* C++11 features, see http://clang.llvm.org/cxx_status.html */ |
| 557 | # if (defined(__cplusplus) && __cplusplus >= 201103L) \ |
| 558 | || defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 559 | /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */ |
| 560 | # if __has_feature(cxx_alignas) |
| 561 | # define Q_COMPILER_ALIGNAS |
| 562 | # define Q_COMPILER_ALIGNOF |
| 563 | # endif |
| 564 | # if __has_feature(cxx_atomic) && __has_include(<atomic>) |
| 565 | # define Q_COMPILER_ATOMICS |
| 566 | # endif |
| 567 | # if __has_feature(cxx_attributes) |
| 568 | # define Q_COMPILER_ATTRIBUTES |
| 569 | # endif |
| 570 | # if __has_feature(cxx_auto_type) |
| 571 | # define Q_COMPILER_AUTO_FUNCTION |
| 572 | # define Q_COMPILER_AUTO_TYPE |
| 573 | # endif |
| 574 | # if __has_feature(cxx_strong_enums) |
| 575 | # define Q_COMPILER_CLASS_ENUM |
| 576 | # endif |
| 577 | # if __has_feature(cxx_constexpr) && Q_CC_CLANG > 302 /* CLANG 3.2 has bad/partial support */ |
| 578 | # define Q_COMPILER_CONSTEXPR |
| 579 | # endif |
| 580 | # if __has_feature(cxx_decltype) /* && __has_feature(cxx_decltype_incomplete_return_types) */ |
| 581 | # define Q_COMPILER_DECLTYPE |
| 582 | # endif |
| 583 | # if __has_feature(cxx_defaulted_functions) |
| 584 | # define Q_COMPILER_DEFAULT_MEMBERS |
| 585 | # endif |
| 586 | # if __has_feature(cxx_deleted_functions) |
| 587 | # define Q_COMPILER_DELETE_MEMBERS |
| 588 | # endif |
| 589 | # if __has_feature(cxx_delegating_constructors) |
| 590 | # define Q_COMPILER_DELEGATING_CONSTRUCTORS |
| 591 | # endif |
| 592 | # if __has_feature(cxx_explicit_conversions) |
| 593 | # define Q_COMPILER_EXPLICIT_CONVERSIONS |
| 594 | # endif |
| 595 | # if __has_feature(cxx_override_control) |
| 596 | # define Q_COMPILER_EXPLICIT_OVERRIDES |
| 597 | # endif |
| 598 | # if __has_feature(cxx_inheriting_constructors) |
| 599 | # define Q_COMPILER_INHERITING_CONSTRUCTORS |
| 600 | # endif |
| 601 | # if __has_feature(cxx_generalized_initializers) |
| 602 | # define Q_COMPILER_INITIALIZER_LISTS |
| 603 | # define Q_COMPILER_UNIFORM_INIT /* both covered by this feature macro, according to docs */ |
| 604 | # endif |
| 605 | # if __has_feature(cxx_lambdas) |
| 606 | # define Q_COMPILER_LAMBDA |
| 607 | # endif |
| 608 | # if __has_feature(cxx_noexcept) |
| 609 | # define Q_COMPILER_NOEXCEPT |
| 610 | # endif |
| 611 | # if __has_feature(cxx_nonstatic_member_init) |
| 612 | # define Q_COMPILER_NONSTATIC_MEMBER_INIT |
| 613 | # endif |
| 614 | # if __has_feature(cxx_nullptr) |
| 615 | # define Q_COMPILER_NULLPTR |
| 616 | # endif |
| 617 | # if __has_feature(cxx_range_for) |
| 618 | # define Q_COMPILER_RANGE_FOR |
| 619 | # endif |
| 620 | # if __has_feature(cxx_raw_string_literals) |
| 621 | # define Q_COMPILER_RAW_STRINGS |
| 622 | # endif |
| 623 | # if __has_feature(cxx_reference_qualified_functions) |
| 624 | # define Q_COMPILER_REF_QUALIFIERS |
| 625 | # endif |
| 626 | # if __has_feature(cxx_rvalue_references) |
| 627 | # define Q_COMPILER_RVALUE_REFS |
| 628 | # endif |
| 629 | # if __has_feature(cxx_static_assert) |
| 630 | # define Q_COMPILER_STATIC_ASSERT |
| 631 | # endif |
| 632 | # if __has_feature(cxx_alias_templates) |
| 633 | # define Q_COMPILER_TEMPLATE_ALIAS |
| 634 | # endif |
| 635 | # if __has_feature(cxx_thread_local) |
| 636 | # if !defined(__FreeBSD__) /* FreeBSD clang fails on __cxa_thread_atexit */ |
| 637 | # define Q_COMPILER_THREAD_LOCAL |
| 638 | # endif |
| 639 | # endif |
| 640 | # if __has_feature(cxx_user_literals) |
| 641 | # define Q_COMPILER_UDL |
| 642 | # endif |
| 643 | # if __has_feature(cxx_unicode_literals) |
| 644 | # define Q_COMPILER_UNICODE_STRINGS |
| 645 | # endif |
| 646 | # if __has_feature(cxx_unrestricted_unions) |
| 647 | # define Q_COMPILER_UNRESTRICTED_UNIONS |
| 648 | # endif |
| 649 | # if __has_feature(cxx_variadic_templates) |
| 650 | # define Q_COMPILER_VARIADIC_TEMPLATES |
| 651 | # endif |
| 652 | /* Features that have no __has_feature() check */ |
| 653 | # if Q_CC_CLANG >= 209 /* since clang 2.9 */ |
| 654 | # define Q_COMPILER_EXTERN_TEMPLATES |
| 655 | # endif |
| 656 | # endif // (defined(__cplusplus) && __cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 657 | |
| 658 | /* C++1y features, deprecated macros. Do not update this list. */ |
| 659 | # if defined(__cplusplus) && __cplusplus > 201103L |
| 660 | //# if __has_feature(cxx_binary_literals) |
| 661 | //# define Q_COMPILER_BINARY_LITERALS // see above |
| 662 | //# endif |
| 663 | # if __has_feature(cxx_generic_lambda) |
| 664 | # define Q_COMPILER_GENERIC_LAMBDA |
| 665 | # endif |
| 666 | # if __has_feature(cxx_init_capture) |
| 667 | # define Q_COMPILER_LAMBDA_CAPTURES |
| 668 | # endif |
| 669 | # if __has_feature(cxx_relaxed_constexpr) |
| 670 | # define Q_COMPILER_RELAXED_CONSTEXPR_FUNCTIONS |
| 671 | # endif |
| 672 | # if __has_feature(cxx_decltype_auto) && __has_feature(cxx_return_type_deduction) |
| 673 | # define Q_COMPILER_RETURN_TYPE_DEDUCTION |
| 674 | # endif |
| 675 | # if __has_feature(cxx_variable_templates) |
| 676 | # define Q_COMPILER_VARIABLE_TEMPLATES |
| 677 | # endif |
| 678 | # if __has_feature(cxx_runtime_array) |
| 679 | # define Q_COMPILER_VLA |
| 680 | # endif |
| 681 | # endif // if defined(__cplusplus) && __cplusplus > 201103L |
| 682 | |
| 683 | # if defined(__STDC_VERSION__) |
| 684 | # if __has_feature(c_static_assert) |
| 685 | # define Q_COMPILER_STATIC_ASSERT |
| 686 | # endif |
| 687 | # if __has_feature(c_thread_local) && __has_include(<threads.h>) |
| 688 | # if !defined(__FreeBSD__) /* FreeBSD clang fails on __cxa_thread_atexit */ |
| 689 | # define Q_COMPILER_THREAD_LOCAL |
| 690 | # endif |
| 691 | # endif |
| 692 | # endif |
| 693 | |
| 694 | # ifndef Q_DECL_UNUSED |
| 695 | # define Q_DECL_UNUSED __attribute__((__unused__)) |
| 696 | # endif |
| 697 | # define Q_DECL_UNUSED_MEMBER Q_DECL_UNUSED |
| 698 | #endif // defined(Q_CC_CLANG) |
| 699 | |
| 700 | #if defined(Q_CC_GNU_ONLY) |
| 701 | # define Q_COMPILER_RESTRICTED_VLA |
| 702 | # if Q_CC_GNU >= 403 |
| 703 | // GCC supports binary literals in C, C++98 and C++11 modes |
| 704 | # define Q_COMPILER_BINARY_LITERALS |
| 705 | # endif |
| 706 | # if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \ |
| 707 | || (defined(__cplusplus) && (__cplusplus >= 201103L)) \ |
| 708 | || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) |
| 709 | // Variadic macros are supported for gnu++98, c++11, C99 ... since forever (gcc 2.97) |
| 710 | # define Q_COMPILER_VARIADIC_MACROS |
| 711 | # endif |
| 712 | # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L |
| 713 | # if Q_CC_GNU >= 403 |
| 714 | /* C++11 features supported in GCC 4.3: */ |
| 715 | # define Q_COMPILER_DECLTYPE |
| 716 | # define Q_COMPILER_RVALUE_REFS |
| 717 | # define Q_COMPILER_STATIC_ASSERT |
| 718 | # endif |
| 719 | # if Q_CC_GNU >= 404 |
| 720 | /* C++11 features supported in GCC 4.4: */ |
| 721 | # define Q_COMPILER_AUTO_FUNCTION |
| 722 | # define Q_COMPILER_AUTO_TYPE |
| 723 | # define Q_COMPILER_EXTERN_TEMPLATES |
| 724 | # define Q_COMPILER_UNIFORM_INIT |
| 725 | # define Q_COMPILER_UNICODE_STRINGS |
| 726 | # define Q_COMPILER_VARIADIC_TEMPLATES |
| 727 | # endif |
| 728 | # if Q_CC_GNU >= 405 |
| 729 | /* C++11 features supported in GCC 4.5: */ |
| 730 | # define Q_COMPILER_EXPLICIT_CONVERSIONS |
| 731 | /* GCC 4.4 implements initializer_list but does not define typedefs required |
| 732 | * by the standard. */ |
| 733 | # define Q_COMPILER_INITIALIZER_LISTS |
| 734 | # define Q_COMPILER_LAMBDA |
| 735 | # define Q_COMPILER_RAW_STRINGS |
| 736 | # define Q_COMPILER_CLASS_ENUM |
| 737 | # endif |
| 738 | # if Q_CC_GNU >= 406 |
| 739 | /* Pre-4.6 compilers implement a non-final snapshot of N2346, hence default and delete |
| 740 | * functions are supported only if they are public. Starting from 4.6, GCC handles |
| 741 | * final version - the access modifier is not relevant. */ |
| 742 | # define Q_COMPILER_DEFAULT_MEMBERS |
| 743 | # define Q_COMPILER_DELETE_MEMBERS |
| 744 | /* C++11 features supported in GCC 4.6: */ |
| 745 | # define Q_COMPILER_NULLPTR |
| 746 | # define Q_COMPILER_UNRESTRICTED_UNIONS |
| 747 | # define Q_COMPILER_RANGE_FOR |
| 748 | # endif |
| 749 | # if Q_CC_GNU >= 407 |
| 750 | /* GCC 4.4 implemented <atomic> and std::atomic using its old intrinsics. |
| 751 | * However, the implementation is incomplete for most platforms until GCC 4.7: |
| 752 | * instead, std::atomic would use an external lock. Since we need an std::atomic |
| 753 | * that is behavior-compatible with QBasicAtomic, we only enable it here */ |
| 754 | # define Q_COMPILER_ATOMICS |
| 755 | /* GCC 4.6.x has problems dealing with noexcept expressions, |
| 756 | * so turn the feature on for 4.7 and above, only */ |
| 757 | # define Q_COMPILER_NOEXCEPT |
| 758 | /* C++11 features supported in GCC 4.7: */ |
| 759 | # define Q_COMPILER_NONSTATIC_MEMBER_INIT |
| 760 | # define Q_COMPILER_DELEGATING_CONSTRUCTORS |
| 761 | # define Q_COMPILER_EXPLICIT_OVERRIDES |
| 762 | # define Q_COMPILER_TEMPLATE_ALIAS |
| 763 | # define Q_COMPILER_UDL |
| 764 | # endif |
| 765 | # if Q_CC_GNU >= 408 |
| 766 | # define Q_COMPILER_ATTRIBUTES |
| 767 | # define Q_COMPILER_ALIGNAS |
| 768 | # define Q_COMPILER_ALIGNOF |
| 769 | # define Q_COMPILER_INHERITING_CONSTRUCTORS |
| 770 | # define Q_COMPILER_THREAD_LOCAL |
| 771 | # if Q_CC_GNU > 408 || __GNUC_PATCHLEVEL__ >= 1 |
| 772 | # define Q_COMPILER_REF_QUALIFIERS |
| 773 | # endif |
| 774 | # endif |
| 775 | # if Q_CC_GNU >= 500 |
| 776 | /* GCC 4.6 introduces constexpr, but it's bugged (at least) in the whole |
| 777 | * 4.x series, see e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57694 */ |
| 778 | # define Q_COMPILER_CONSTEXPR |
| 779 | # endif |
| 780 | # endif |
| 781 | # if __cplusplus > 201103L |
| 782 | # if Q_CC_GNU >= 409 |
| 783 | /* C++1y features in GCC 4.9 - deprecated, do not update this list */ |
| 784 | //# define Q_COMPILER_BINARY_LITERALS // already supported since GCC 4.3 as an extension |
| 785 | # define Q_COMPILER_LAMBDA_CAPTURES |
| 786 | # define Q_COMPILER_RETURN_TYPE_DEDUCTION |
| 787 | # endif |
| 788 | # endif |
| 789 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L |
| 790 | # if Q_CC_GNU >= 407 |
| 791 | /* C11 features supported in GCC 4.7: */ |
| 792 | # define Q_COMPILER_STATIC_ASSERT |
| 793 | # endif |
| 794 | # if Q_CC_GNU >= 409 && defined(__has_include) |
| 795 | /* C11 features supported in GCC 4.9: */ |
| 796 | # if __has_include(<threads.h>) |
| 797 | # define Q_COMPILER_THREAD_LOCAL |
| 798 | # endif |
| 799 | # endif |
| 800 | # endif |
| 801 | #endif |
| 802 | |
| 803 | #if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) |
| 804 | # if defined(__cplusplus) |
| 805 | /* C++11 features supported in VC8 = VC2005: */ |
| 806 | # define Q_COMPILER_VARIADIC_MACROS |
| 807 | |
| 808 | /* 2005 supports the override and final contextual keywords, in |
| 809 | the same positions as the C++11 variants, but 'final' is |
| 810 | called 'sealed' instead: |
| 811 | http://msdn.microsoft.com/en-us/library/0w2w91tf%28v=vs.80%29.aspx |
| 812 | The behavior is slightly different in C++/CLI, which requires the |
| 813 | "virtual" keyword to be present too, so don't define for that. |
| 814 | So don't define Q_COMPILER_EXPLICIT_OVERRIDES (since it's not |
| 815 | the same as the C++11 version), but define the Q_DECL_* flags |
| 816 | accordingly. */ |
| 817 | /* C++11 features supported in VC10 = VC2010: */ |
| 818 | # define Q_COMPILER_AUTO_FUNCTION |
| 819 | # define Q_COMPILER_AUTO_TYPE |
| 820 | # define Q_COMPILER_DECLTYPE |
| 821 | # define Q_COMPILER_EXTERN_TEMPLATES |
| 822 | # define Q_COMPILER_LAMBDA |
| 823 | # define Q_COMPILER_NULLPTR |
| 824 | # define Q_COMPILER_RVALUE_REFS |
| 825 | # define Q_COMPILER_STATIC_ASSERT |
| 826 | /* C++11 features supported in VC11 = VC2012: */ |
| 827 | # define Q_COMPILER_EXPLICIT_OVERRIDES /* ...and use std C++11 now */ |
| 828 | # define Q_COMPILER_CLASS_ENUM |
| 829 | # define Q_COMPILER_ATOMICS |
| 830 | /* C++11 features in VC12 = VC2013 */ |
| 831 | # define Q_COMPILER_DELETE_MEMBERS |
| 832 | # define Q_COMPILER_DELEGATING_CONSTRUCTORS |
| 833 | # define Q_COMPILER_EXPLICIT_CONVERSIONS |
| 834 | # define Q_COMPILER_NONSTATIC_MEMBER_INIT |
| 835 | # define Q_COMPILER_RAW_STRINGS |
| 836 | # define Q_COMPILER_TEMPLATE_ALIAS |
| 837 | # define Q_COMPILER_VARIADIC_TEMPLATES |
| 838 | # define Q_COMPILER_INITIALIZER_LISTS // VC 12 SP 2 RC |
| 839 | /* C++11 features in VC14 = VC2015 */ |
| 840 | # define Q_COMPILER_DEFAULT_MEMBERS |
| 841 | # define Q_COMPILER_ALIGNAS |
| 842 | # define Q_COMPILER_ALIGNOF |
| 843 | # define Q_COMPILER_INHERITING_CONSTRUCTORS |
| 844 | # define Q_COMPILER_NOEXCEPT |
| 845 | # define Q_COMPILER_RANGE_FOR |
| 846 | # define Q_COMPILER_REF_QUALIFIERS |
| 847 | # define Q_COMPILER_THREAD_LOCAL |
| 848 | # define Q_COMPILER_UDL |
| 849 | # define Q_COMPILER_UNICODE_STRINGS |
| 850 | # define Q_COMPILER_UNRESTRICTED_UNIONS |
| 851 | # if _MSC_FULL_VER >= 190023419 |
| 852 | # define Q_COMPILER_ATTRIBUTES |
| 853 | // Almost working, see https://connect.microsoft.com/VisualStudio/feedback/details/2011648 |
| 854 | //# define Q_COMPILER_CONSTEXPR |
| 855 | # define Q_COMPILER_UNIFORM_INIT |
| 856 | # endif |
| 857 | # if _MSC_VER >= 1910 |
| 858 | # define Q_COMPILER_CONSTEXPR |
| 859 | # endif |
| 860 | // MSVC versions before 19.36 have a bug in C++20 comparison implementation. |
| 861 | // This leads to ambiguities when resolving comparison operator overloads in |
| 862 | // certain scenarios (the buggy MSVC versions were checked using our CI and |
| 863 | // compiler explorer). |
| 864 | # if _MSC_VER < 1936 |
| 865 | # define Q_COMPILER_LACKS_THREE_WAY_COMPARE_SYMMETRY |
| 866 | # endif |
| 867 | // QTBUG-124376: MSVC is slow at compiling qstrnlen() |
| 868 | # define Q_COMPILER_SLOW_QSTRNLEN_COMPILATION |
| 869 | # endif /* __cplusplus */ |
| 870 | #endif // defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) |
| 871 | |
| 872 | #ifdef Q_COMPILER_UNICODE_STRINGS |
| 873 | # define Q_STDLIB_UNICODE_STRINGS |
| 874 | #elif defined(__cplusplus) |
| 875 | # error "Qt6 requires Unicode string support in both the compiler and the standard library" |
| 876 | #endif |
| 877 | |
| 878 | #ifdef __cplusplus |
| 879 | # include <utility> |
| 880 | # if defined(Q_OS_QNX) |
| 881 | // By default, QNX 7.0 uses libc++ (from LLVM) and |
| 882 | // QNX 6.X uses Dinkumware's libcpp. In all versions, |
| 883 | // it is also possible to use GNU libstdc++. |
| 884 | |
| 885 | // For Dinkumware, some features must be disabled |
| 886 | // (mostly because of library problems). |
| 887 | // Dinkumware is assumed when __GLIBCXX__ (GNU libstdc++) |
| 888 | // and _LIBCPP_VERSION (LLVM libc++) are both absent. |
| 889 | # if !defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) |
| 890 | |
| 891 | // Older versions of libcpp (QNX 650) do not support C++11 features |
| 892 | // _HAS_* macros are set to 1 by toolchains that actually include |
| 893 | // Dinkum C++11 libcpp. |
| 894 | |
| 895 | # if !defined(_HAS_CPP0X) || !_HAS_CPP0X |
| 896 | // Disable C++11 features that depend on library support |
| 897 | # undef Q_COMPILER_INITIALIZER_LISTS |
| 898 | # undef Q_COMPILER_RVALUE_REFS |
| 899 | # undef Q_COMPILER_REF_QUALIFIERS |
| 900 | # undef Q_COMPILER_NOEXCEPT |
| 901 | // Disable C++11 library features: |
| 902 | # undef Q_STDLIB_UNICODE_STRINGS |
| 903 | # endif // !_HAS_CPP0X |
| 904 | # if !defined(_HAS_NULLPTR_T) || !_HAS_NULLPTR_T |
| 905 | # undef Q_COMPILER_NULLPTR |
| 906 | # endif //!_HAS_NULLPTR_T |
| 907 | # if !defined(_HAS_CONSTEXPR) || !_HAS_CONSTEXPR |
| 908 | // The libcpp is missing constexpr keywords on important functions like std::numeric_limits<>::min() |
| 909 | // Disable constexpr support on QNX even if the compiler supports it |
| 910 | # undef Q_COMPILER_CONSTEXPR |
| 911 | # endif // !_HAS_CONSTEXPR |
| 912 | # endif // !__GLIBCXX__ && !_LIBCPP_VERSION |
| 913 | # endif // Q_OS_QNX |
| 914 | # if defined(Q_CC_CLANG) && defined(Q_OS_DARWIN) |
| 915 | # if defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402) |
| 916 | // Apple has not updated libstdc++ since 2007, which means it does not have |
| 917 | // <initializer_list> or std::move. Let's disable these features |
| 918 | # undef Q_COMPILER_INITIALIZER_LISTS |
| 919 | # undef Q_COMPILER_RVALUE_REFS |
| 920 | # undef Q_COMPILER_REF_QUALIFIERS |
| 921 | // Also disable <atomic>, since it's clearly not there |
| 922 | # undef Q_COMPILER_ATOMICS |
| 923 | # endif |
| 924 | # if defined(__cpp_lib_memory_resource) \ |
| 925 | && ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 140000) \ |
| 926 | || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 170000)) |
| 927 | # undef __cpp_lib_memory_resource // Only supported on macOS 14 and iOS 17 |
| 928 | # endif |
| 929 | # endif // defined(Q_CC_CLANG) && defined(Q_OS_DARWIN) |
| 930 | #endif |
| 931 | |
| 932 | // Don't break code that is already using Q_COMPILER_DEFAULT_DELETE_MEMBERS |
| 933 | #if defined(Q_COMPILER_DEFAULT_MEMBERS) && defined(Q_COMPILER_DELETE_MEMBERS) |
| 934 | # define Q_COMPILER_DEFAULT_DELETE_MEMBERS |
| 935 | #endif |
| 936 | |
| 937 | /* |
| 938 | * Compatibility macros for C++11/14 keywords and expressions. |
| 939 | * Don't use in new code and port away whenever you have a chance. |
| 940 | */ |
| 941 | #define Q_ALIGNOF(x) alignof(x) |
| 942 | #define Q_DECL_ALIGN(n) alignas(n) |
| 943 | #define Q_DECL_NOTHROW Q_DECL_NOEXCEPT |
| 944 | #ifdef __cplusplus |
| 945 | # define Q_CONSTEXPR constexpr |
| 946 | # define Q_DECL_CONSTEXPR constexpr |
| 947 | # define Q_DECL_EQ_DEFAULT = default |
| 948 | # define Q_DECL_EQ_DELETE = delete |
| 949 | # define Q_DECL_FINAL final |
| 950 | # define Q_DECL_NOEXCEPT noexcept |
| 951 | # define Q_DECL_NOEXCEPT_EXPR(x) noexcept(x) |
| 952 | # define Q_DECL_OVERRIDE override |
| 953 | # define Q_DECL_RELAXED_CONSTEXPR constexpr |
| 954 | # define Q_NULLPTR nullptr |
| 955 | # define Q_RELAXED_CONSTEXPR constexpr |
| 956 | #else |
| 957 | # define Q_CONSTEXPR const |
| 958 | # define Q_DECL_CONSTEXPR |
| 959 | # define Q_DECL_RELAXED_CONSTEXPR |
| 960 | # define Q_NULLPTR NULL |
| 961 | # define Q_RELAXED_CONSTEXPR const |
| 962 | # ifdef Q_CC_GNU |
| 963 | # define Q_DECL_NOEXCEPT __attribute__((__nothrow__)) |
| 964 | # else |
| 965 | # define Q_DECL_NOEXCEPT |
| 966 | # endif |
| 967 | #endif |
| 968 | |
| 969 | #if (defined(__cplusplus) && __has_cpp_attribute(nodiscard) /* P0188R1 */) || \ |
| 970 | (!defined(__cplusplus) && __has_c_attribute(nodiscard) /* N2267 */) |
| 971 | # undef Q_REQUIRED_RESULT |
| 972 | # define Q_REQUIRED_RESULT [[nodiscard]] |
| 973 | #endif |
| 974 | |
| 975 | #if (defined(__cplusplus) && __has_cpp_attribute(nodiscard) >= 201907L /* used for both P1771 and P1301... */) \ |
| 976 | || (!defined(__cplusplus) && __has_c_attribute(nodiscard) /* N2448 */) |
| 977 | // [[nodiscard]] constructor (P1771) |
| 978 | # ifndef Q_NODISCARD_CTOR |
| 979 | # define Q_NODISCARD_CTOR [[nodiscard]] |
| 980 | # endif |
| 981 | // [[nodiscard("reason")]] (P1301, N2448 for C) |
| 982 | # ifndef Q_NODISCARD_X |
| 983 | # define Q_NODISCARD_X(message) [[nodiscard(message)]] |
| 984 | # endif |
| 985 | # ifndef Q_NODISCARD_CTOR_X |
| 986 | # define Q_NODISCARD_CTOR_X(message) [[nodiscard(message)]] |
| 987 | # endif |
| 988 | #endif |
| 989 | |
| 990 | #if (defined(__cplusplus) && __has_cpp_attribute(maybe_unused)) || \ |
| 991 | (!defined(__cplusplus) && __has_c_attribute(maybe_unused)) |
| 992 | # undef Q_DECL_UNUSED |
| 993 | # define Q_DECL_UNUSED [[maybe_unused]] |
| 994 | #endif |
| 995 | |
| 996 | #if (defined(__cplusplus) && __has_cpp_attribute(noreturn)) || \ |
| 997 | (!defined(__cplusplus) && __has_c_attribute(noreturn)) |
| 998 | # undef Q_NORETURN |
| 999 | # define Q_NORETURN [[noreturn]] |
| 1000 | #endif |
| 1001 | |
| 1002 | #if (defined(__cplusplus) && __has_cpp_attribute(deprecated)) || \ |
| 1003 | (!defined(__cplusplus) && __has_c_attribute(deprecated)) |
| 1004 | # ifdef Q_DECL_DEPRECATED |
| 1005 | # undef Q_DECL_DEPRECATED |
| 1006 | # endif |
| 1007 | # ifdef Q_DECL_DEPRECATED_X |
| 1008 | # undef Q_DECL_DEPRECATED_X |
| 1009 | # endif |
| 1010 | # define Q_DECL_DEPRECATED [[deprecated]] |
| 1011 | # define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]] |
| 1012 | #endif |
| 1013 | |
| 1014 | #define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED |
| 1015 | #define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x) |
| 1016 | |
| 1017 | #ifndef Q_DECL_CONSTEXPR_DTOR |
| 1018 | # if __cpp_constexpr >= 201907L |
| 1019 | # define Q_DECL_CONSTEXPR_DTOR constexpr |
| 1020 | # else |
| 1021 | # define Q_DECL_CONSTEXPR_DTOR inline |
| 1022 | # endif |
| 1023 | #endif |
| 1024 | |
| 1025 | #ifndef Q_CONSTEXPR_DTOR |
| 1026 | # if __cpp_constexpr >= 201907L |
| 1027 | # define Q_CONSTEXPR_DTOR constexpr |
| 1028 | # else |
| 1029 | # define Q_CONSTEXPR_DTOR const |
| 1030 | # endif |
| 1031 | #endif |
| 1032 | |
| 1033 | #ifndef Q_DECL_EQ_DELETE_X |
| 1034 | // Clang < 20 advertises the feature-testing macro but issues a warning |
| 1035 | // if one isn't also using C++26, |
| 1036 | // https://github.com/llvm/llvm-project/issues/109311 |
| 1037 | # if defined(__cpp_deleted_function) && __cpp_deleted_function >= 202403L \ |
| 1038 | && (!defined(Q_CC_CLANG_ONLY) || Q_CC_CLANG_ONLY >= 2010 || __cplusplus > 202302L) // C++26 |
| 1039 | # define Q_DECL_EQ_DELETE_X(reason) = delete(reason) |
| 1040 | # else |
| 1041 | # define Q_DECL_EQ_DELETE_X(reason) = delete |
| 1042 | # endif |
| 1043 | #endif |
| 1044 | |
| 1045 | #ifndef Q_LIKELY_BRANCH |
| 1046 | # if __has_cpp_attribute(likely) |
| 1047 | # define Q_LIKELY_BRANCH [[likely]] |
| 1048 | # define Q_UNLIKELY_BRANCH [[unlikely]] |
| 1049 | # else |
| 1050 | # define Q_LIKELY_BRANCH |
| 1051 | # define Q_UNLIKELY_BRANCH |
| 1052 | # endif |
| 1053 | #endif |
| 1054 | |
| 1055 | /* |
| 1056 | * Fallback macros to certain compiler features |
| 1057 | */ |
| 1058 | |
| 1059 | #ifndef Q_NORETURN |
| 1060 | # define Q_NORETURN |
| 1061 | #endif |
| 1062 | #ifndef Q_LIKELY |
| 1063 | # define Q_LIKELY(x) (x) |
| 1064 | #endif |
| 1065 | #ifndef Q_UNLIKELY |
| 1066 | # define Q_UNLIKELY(x) (x) |
| 1067 | #endif |
| 1068 | #ifndef Q_ASSUME_IMPL |
| 1069 | # define Q_ASSUME_IMPL(expr) qt_noop() |
| 1070 | #endif |
| 1071 | #ifndef Q_UNREACHABLE_IMPL |
| 1072 | # define Q_UNREACHABLE_IMPL() qt_noop() |
| 1073 | #endif |
| 1074 | #ifndef Q_ALLOC_SIZE |
| 1075 | # define Q_ALLOC_SIZE(x) |
| 1076 | #endif |
| 1077 | #ifndef Q_REQUIRED_RESULT |
| 1078 | # define Q_REQUIRED_RESULT |
| 1079 | #endif |
| 1080 | #ifndef Q_NODISCARD_X |
| 1081 | # define Q_NODISCARD_X(message) Q_REQUIRED_RESULT |
| 1082 | #endif |
| 1083 | #ifndef Q_NODISCARD_CTOR |
| 1084 | # define Q_NODISCARD_CTOR |
| 1085 | #endif |
| 1086 | #ifndef Q_NODISCARD_CTOR_X |
| 1087 | # define Q_NODISCARD_CTOR_X(message) Q_NODISCARD_CTOR |
| 1088 | #endif |
| 1089 | #ifndef Q_DECL_DEPRECATED |
| 1090 | # define Q_DECL_DEPRECATED |
| 1091 | #endif |
| 1092 | #ifndef Q_DECL_VARIABLE_DEPRECATED |
| 1093 | # define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED |
| 1094 | #endif |
| 1095 | #ifndef Q_DECL_DEPRECATED_X |
| 1096 | # define Q_DECL_DEPRECATED_X(text) Q_DECL_DEPRECATED |
| 1097 | #endif |
| 1098 | #ifndef Q_DECL_EXPORT |
| 1099 | # define Q_DECL_EXPORT |
| 1100 | #endif |
| 1101 | #ifndef Q_DECL_EXPORT_OVERRIDABLE |
| 1102 | # define Q_DECL_EXPORT_OVERRIDABLE Q_DECL_EXPORT |
| 1103 | #endif |
| 1104 | #ifndef Q_DECL_IMPORT |
| 1105 | # define Q_DECL_IMPORT |
| 1106 | #endif |
| 1107 | #ifndef Q_DECL_HIDDEN |
| 1108 | # define Q_DECL_HIDDEN |
| 1109 | #endif |
| 1110 | #ifndef Q_DECL_UNUSED |
| 1111 | # define Q_DECL_UNUSED |
| 1112 | #endif |
| 1113 | #ifndef Q_DECL_UNUSED_MEMBER |
| 1114 | # define Q_DECL_UNUSED_MEMBER |
| 1115 | #endif |
| 1116 | #ifndef Q_FUNC_INFO |
| 1117 | # if defined(Q_OS_SOLARIS) || defined(Q_CC_XLC) |
| 1118 | # define Q_FUNC_INFO __FILE__ "(line number unavailable)" |
| 1119 | # else |
| 1120 | # define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__) |
| 1121 | # endif |
| 1122 | #endif |
| 1123 | #ifndef Q_DECL_CF_RETURNS_RETAINED |
| 1124 | # define Q_DECL_CF_RETURNS_RETAINED |
| 1125 | #endif |
| 1126 | #ifndef Q_DECL_NS_RETURNS_AUTORELEASED |
| 1127 | # define Q_DECL_NS_RETURNS_AUTORELEASED |
| 1128 | #endif |
| 1129 | #ifndef Q_DECL_PURE_FUNCTION |
| 1130 | # define Q_DECL_PURE_FUNCTION |
| 1131 | #endif |
| 1132 | #ifndef Q_DECL_CONST_FUNCTION |
| 1133 | # define Q_DECL_CONST_FUNCTION Q_DECL_PURE_FUNCTION |
| 1134 | #endif |
| 1135 | #ifndef Q_DECL_COLD_FUNCTION |
| 1136 | # define Q_DECL_COLD_FUNCTION |
| 1137 | #endif |
| 1138 | #ifndef QT_MAKE_UNCHECKED_ARRAY_ITERATOR |
| 1139 | # define QT_MAKE_UNCHECKED_ARRAY_ITERATOR(x) (x) |
| 1140 | #endif |
| 1141 | #ifndef QT_MAKE_CHECKED_ARRAY_ITERATOR |
| 1142 | # define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x) |
| 1143 | #endif |
| 1144 | |
| 1145 | /* |
| 1146 | * "Weak overloads" - makes an otherwise confliciting overload weaker |
| 1147 | * (by making it a template) |
| 1148 | */ |
| 1149 | #ifndef Q_QDOC |
| 1150 | # define Q_WEAK_OVERLOAD template <typename = void> |
| 1151 | #else |
| 1152 | # define Q_WEAK_OVERLOAD |
| 1153 | #endif |
| 1154 | |
| 1155 | /* |
| 1156 | * If one wants to add functions that use post-C++17 APIs, one needs to: |
| 1157 | * |
| 1158 | * 1) make them fully inline; and |
| 1159 | * 2) guard them using the necessary feature-testing macros. |
| 1160 | * |
| 1161 | * This decouples the C++ version used to build Qt with the one used by |
| 1162 | * end-user applications; Qt and the application can either choose any C++ |
| 1163 | * version. |
| 1164 | * |
| 1165 | * A problem arises on MSVC for member functions of exported classes. Client |
| 1166 | * code that tries to use such a function will see it as exported, and simply |
| 1167 | * try to consume the function's *symbol*. However, if Qt has been built in |
| 1168 | * C++17, it won't have such a symbol, and linking will fail. |
| 1169 | * |
| 1170 | * The workaround: declare such functions as function templates. |
| 1171 | * (Obviously a function template does not need this marker.) |
| 1172 | */ |
| 1173 | #ifndef Q_QDOC |
| 1174 | # define QT_POST_CXX17_API_IN_EXPORTED_CLASS template <typename = void> |
| 1175 | #else |
| 1176 | # define QT_POST_CXX17_API_IN_EXPORTED_CLASS |
| 1177 | #endif |
| 1178 | |
| 1179 | /* |
| 1180 | * Warning/diagnostic handling |
| 1181 | */ |
| 1182 | |
| 1183 | #define QT_DO_PRAGMA(text) _Pragma(#text) |
| 1184 | #if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) |
| 1185 | # undef QT_DO_PRAGMA /* not needed */ |
| 1186 | # define QT_WARNING_PUSH __pragma(warning(push)) |
| 1187 | # define QT_WARNING_POP __pragma(warning(pop)) |
| 1188 | # define QT_WARNING_DISABLE_MSVC(number) __pragma(warning(disable: number)) |
| 1189 | # define QT_WARNING_DISABLE_INTEL(number) |
| 1190 | # define QT_WARNING_DISABLE_CLANG(text) |
| 1191 | # define QT_WARNING_DISABLE_GCC(text) |
| 1192 | # define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_MSVC(4996) |
| 1193 | # define QT_WARNING_DISABLE_FLOAT_COMPARE |
| 1194 | # define QT_WARNING_DISABLE_INVALID_OFFSETOF |
| 1195 | #elif defined(Q_CC_CLANG) |
| 1196 | # define QT_WARNING_PUSH QT_DO_PRAGMA(clang diagnostic push) |
| 1197 | # define QT_WARNING_POP QT_DO_PRAGMA(clang diagnostic pop) |
| 1198 | # define QT_WARNING_DISABLE_CLANG(text) QT_DO_PRAGMA(clang diagnostic ignored text) |
| 1199 | # define QT_WARNING_DISABLE_GCC(text) |
| 1200 | # define QT_WARNING_DISABLE_INTEL(number) |
| 1201 | # define QT_WARNING_DISABLE_MSVC(number) |
| 1202 | # define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") |
| 1203 | # define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_CLANG("-Wfloat-equal") |
| 1204 | # define QT_WARNING_DISABLE_INVALID_OFFSETOF QT_WARNING_DISABLE_CLANG("-Winvalid-offsetof") |
| 1205 | #elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) |
| 1206 | # define QT_WARNING_PUSH QT_DO_PRAGMA(GCC diagnostic push) |
| 1207 | # define QT_WARNING_POP QT_DO_PRAGMA(GCC diagnostic pop) |
| 1208 | # define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text) |
| 1209 | # define QT_WARNING_DISABLE_CLANG(text) |
| 1210 | # define QT_WARNING_DISABLE_INTEL(number) |
| 1211 | # define QT_WARNING_DISABLE_MSVC(number) |
| 1212 | # define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") |
| 1213 | # define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_GCC("-Wfloat-equal") |
| 1214 | # define QT_WARNING_DISABLE_INVALID_OFFSETOF QT_WARNING_DISABLE_GCC("-Winvalid-offsetof") |
| 1215 | #else // All other compilers, GCC < 4.6 and MSVC < 2008 |
| 1216 | # define QT_WARNING_DISABLE_GCC(text) |
| 1217 | # define QT_WARNING_PUSH |
| 1218 | # define QT_WARNING_POP |
| 1219 | # define QT_WARNING_DISABLE_INTEL(number) |
| 1220 | # define QT_WARNING_DISABLE_MSVC(number) |
| 1221 | # define QT_WARNING_DISABLE_CLANG(text) |
| 1222 | # define QT_WARNING_DISABLE_GCC(text) |
| 1223 | # define QT_WARNING_DISABLE_DEPRECATED |
| 1224 | # define QT_WARNING_DISABLE_FLOAT_COMPARE |
| 1225 | # define QT_WARNING_DISABLE_INVALID_OFFSETOF |
| 1226 | #endif |
| 1227 | |
| 1228 | #ifndef QT_IGNORE_DEPRECATIONS |
| 1229 | #define QT_IGNORE_DEPRECATIONS(statement) \ |
| 1230 | QT_WARNING_PUSH \ |
| 1231 | QT_WARNING_DISABLE_DEPRECATED \ |
| 1232 | statement \ |
| 1233 | QT_WARNING_POP |
| 1234 | #endif |
| 1235 | |
| 1236 | // The body must be a statement: |
| 1237 | #define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP |
| 1238 | |
| 1239 | // This macro can be used to calculate member offsets for types with a non standard layout. |
| 1240 | // It uses the fact that offsetof() is allowed to support those types since C++17 as an optional |
| 1241 | // feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof() |
| 1242 | // call in a macro that disables the compiler warning. |
| 1243 | #define Q_OFFSETOF(Class, member) \ |
| 1244 | []() -> size_t { \ |
| 1245 | QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ |
| 1246 | return offsetof(Class, member); \ |
| 1247 | QT_WARNING_POP \ |
| 1248 | }() |
| 1249 | |
| 1250 | /* |
| 1251 | Proper for-scoping in MIPSpro CC |
| 1252 | */ |
| 1253 | #ifndef QT_NO_KEYWORDS |
| 1254 | # if defined(Q_CC_MIPS) || (defined(Q_CC_HPACC) && defined(__ia64)) |
| 1255 | # define for if (0) {} else for |
| 1256 | # endif |
| 1257 | #endif |
| 1258 | |
| 1259 | #ifdef Q_COMPILER_RVALUE_REFS |
| 1260 | #define qMove(x) std::move(x) |
| 1261 | #else |
| 1262 | #define qMove(x) (x) |
| 1263 | #endif |
| 1264 | |
| 1265 | #if defined(__cplusplus) |
| 1266 | #if __has_cpp_attribute(clang::fallthrough) |
| 1267 | # define Q_FALLTHROUGH() [[clang::fallthrough]] |
| 1268 | #elif __has_cpp_attribute(gnu::fallthrough) |
| 1269 | # define Q_FALLTHROUGH() [[gnu::fallthrough]] |
| 1270 | #elif __has_cpp_attribute(fallthrough) |
| 1271 | # define Q_FALLTHROUGH() [[fallthrough]] |
| 1272 | #endif |
| 1273 | #else // !defined(__cplusplus) |
| 1274 | # if __has_c_attribute(fallthrough) |
| 1275 | # define Q_FALLTHROUGH() [[fallthrough]] |
| 1276 | # endif |
| 1277 | #endif // !defined(__cplusplus) |
| 1278 | #ifndef Q_FALLTHROUGH |
| 1279 | # ifdef Q_CC_GNU |
| 1280 | # define Q_FALLTHROUGH() __attribute__((fallthrough)) |
| 1281 | # else |
| 1282 | # define Q_FALLTHROUGH() (void)0 |
| 1283 | # endif |
| 1284 | #endif |
| 1285 | |
| 1286 | #if defined(__has_attribute) && __has_attribute(uninitialized) |
| 1287 | # define Q_DECL_UNINITIALIZED __attribute__((uninitialized)) |
| 1288 | #else |
| 1289 | # define Q_DECL_UNINITIALIZED |
| 1290 | #endif |
| 1291 | |
| 1292 | |
| 1293 | /* |
| 1294 | Sanitize compiler feature availability |
| 1295 | */ |
| 1296 | #if !defined(Q_PROCESSOR_X86) |
| 1297 | # undef QT_COMPILER_SUPPORTS_SSE2 |
| 1298 | # undef QT_COMPILER_SUPPORTS_SSE3 |
| 1299 | # undef QT_COMPILER_SUPPORTS_SSSE3 |
| 1300 | # undef QT_COMPILER_SUPPORTS_SSE4_1 |
| 1301 | # undef QT_COMPILER_SUPPORTS_SSE4_2 |
| 1302 | # undef QT_COMPILER_SUPPORTS_AVX |
| 1303 | # undef QT_COMPILER_SUPPORTS_AVX2 |
| 1304 | # undef QT_COMPILER_SUPPORTS_F16C |
| 1305 | #endif |
| 1306 | #if !defined(Q_PROCESSOR_ARM) |
| 1307 | # undef QT_COMPILER_SUPPORTS_NEON |
| 1308 | #endif |
| 1309 | #if !defined(Q_PROCESSOR_MIPS) |
| 1310 | # undef QT_COMPILER_SUPPORTS_MIPS_DSP |
| 1311 | # undef QT_COMPILER_SUPPORTS_MIPS_DSPR2 |
| 1312 | #endif |
| 1313 | |
| 1314 | // Compiler version check |
| 1315 | #if defined(__cplusplus) && (__cplusplus < 201703L) |
| 1316 | # ifdef Q_CC_MSVC |
| 1317 | # error "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." |
| 1318 | # else |
| 1319 | # error "Qt requires a C++17 compiler" |
| 1320 | # endif |
| 1321 | #endif // __cplusplus |
| 1322 | |
| 1323 | #if defined(__cplusplus) && defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) |
| 1324 | # if Q_CC_MSVC < 1927 |
| 1325 | // Check below only works with 16.7 or newer |
| 1326 | # error "Qt requires at least Visual Studio 2019 version 16.7 (VC++ version 14.27). Please upgrade." |
| 1327 | # endif |
| 1328 | |
| 1329 | // On MSVC we require /permissive- set by user code. Check that we are |
| 1330 | // under its rules -- for instance, check that std::nullptr_t->bool is |
| 1331 | // not an implicit conversion, as per |
| 1332 | // https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160#nullptr_t-is-only-convertible-to-bool-as-a-direct-initialization |
| 1333 | static_assert(!std::is_convertible_v<std::nullptr_t, bool>, |
| 1334 | "On MSVC you must pass the /permissive- option to the compiler." ); |
| 1335 | #endif |
| 1336 | |
| 1337 | #if defined(QT_BOOTSTRAPPED) || defined(QT_USE_PROTECTED_VISIBILITY) || !defined(__ELF__) || defined(__PIC__) |
| 1338 | // this is fine |
| 1339 | #elif defined(__PIE__) |
| 1340 | # error "-fPIE is not sufficient if Qt was configured with the -DFEATURE_reduce_relocations=ON "\ |
| 1341 | "CMake option. Compile your code with -fPIC and without -fPIE or compile Qt with "\ |
| 1342 | "-DFEATURE_no_direct_extern_access=ON." |
| 1343 | #elif defined(QT_REDUCE_RELOCATIONS) |
| 1344 | # error "You must build your code with position independent code if Qt was configured with the "\ |
| 1345 | "-DFEATURE_reduce_relocations=ON CMake option. Compile your code with -fPIC and "\ |
| 1346 | "without -fPIE or compile Qt with -DFEATURE_no_direct_extern_access=ON." |
| 1347 | #endif |
| 1348 | |
| 1349 | #ifdef Q_PROCESSOR_X86_32 |
| 1350 | # if defined(Q_CC_GNU) |
| 1351 | # define QT_FASTCALL __attribute__((regparm(3))) |
| 1352 | # elif defined(Q_CC_MSVC) |
| 1353 | # define QT_FASTCALL __fastcall |
| 1354 | # else |
| 1355 | # define QT_FASTCALL |
| 1356 | # endif |
| 1357 | #else |
| 1358 | # define QT_FASTCALL |
| 1359 | #endif |
| 1360 | |
| 1361 | // enable gcc warnings for printf-style functions |
| 1362 | #if defined(Q_CC_GNU) && !defined(__INSURE__) |
| 1363 | # if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) |
| 1364 | # define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \ |
| 1365 | __attribute__((format(gnu_printf, (A), (B)))) |
| 1366 | # else |
| 1367 | # define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \ |
| 1368 | __attribute__((format(printf, (A), (B)))) |
| 1369 | # endif |
| 1370 | #else |
| 1371 | # define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) |
| 1372 | #endif |
| 1373 | |
| 1374 | #ifdef Q_CC_MSVC |
| 1375 | # define Q_NEVER_INLINE __declspec(noinline) |
| 1376 | # define Q_ALWAYS_INLINE __forceinline |
| 1377 | #elif defined(Q_CC_GNU) |
| 1378 | # define Q_NEVER_INLINE __attribute__((noinline)) |
| 1379 | # define Q_ALWAYS_INLINE inline __attribute__((always_inline)) |
| 1380 | #else |
| 1381 | # define Q_NEVER_INLINE |
| 1382 | # define Q_ALWAYS_INLINE inline |
| 1383 | #endif |
| 1384 | |
| 1385 | //defines the type for the WNDPROC on windows |
| 1386 | //the alignment needs to be forced for sse2 to not crash with mingw |
| 1387 | #if defined(Q_OS_WIN) |
| 1388 | # if defined(Q_CC_MINGW) && defined(Q_PROCESSOR_X86_32) |
| 1389 | # define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer)) |
| 1390 | # else |
| 1391 | # define QT_ENSURE_STACK_ALIGNED_FOR_SSE |
| 1392 | # endif |
| 1393 | # define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE |
| 1394 | #endif |
| 1395 | |
| 1396 | #ifdef __cpp_conditional_explicit |
| 1397 | #define Q_IMPLICIT explicit(false) |
| 1398 | #else |
| 1399 | #define Q_IMPLICIT |
| 1400 | #endif |
| 1401 | |
| 1402 | #if defined(__cplusplus) |
| 1403 | |
| 1404 | #ifdef __cpp_constinit |
| 1405 | # if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) |
| 1406 | // https://developercommunity.visualstudio.com/t/C:-constinit-for-an-optional-fails-if-/1406069 |
| 1407 | # define Q_CONSTINIT |
| 1408 | # else |
| 1409 | # define Q_CONSTINIT constinit |
| 1410 | # endif |
| 1411 | #elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::require_constant_initialization) |
| 1412 | # define Q_CONSTINIT [[clang::require_constant_initialization]] |
| 1413 | #elif defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1000 |
| 1414 | # define Q_CONSTINIT __constinit |
| 1415 | #else |
| 1416 | # define Q_CONSTINIT |
| 1417 | #endif |
| 1418 | |
| 1419 | #ifndef Q_OUTOFLINE_TEMPLATE |
| 1420 | # define Q_OUTOFLINE_TEMPLATE |
| 1421 | #endif |
| 1422 | #ifndef Q_INLINE_TEMPLATE |
| 1423 | # define Q_INLINE_TEMPLATE inline |
| 1424 | #endif |
| 1425 | |
| 1426 | /* |
| 1427 | Avoid some particularly useless warnings from some stupid compilers. |
| 1428 | To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out |
| 1429 | the line "#define QT_NO_WARNINGS". See also QTBUG-26877. |
| 1430 | */ |
| 1431 | #if !defined(QT_CC_WARNINGS) |
| 1432 | # define QT_NO_WARNINGS |
| 1433 | #endif |
| 1434 | #if defined(QT_NO_WARNINGS) |
| 1435 | # if defined(Q_CC_MSVC) |
| 1436 | QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */ |
| 1437 | QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */ |
| 1438 | QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */ |
| 1439 | QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */ |
| 1440 | QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */ |
| 1441 | QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */ |
| 1442 | QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */ |
| 1443 | QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */ |
| 1444 | QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */ |
| 1445 | QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */ |
| 1446 | # elif defined(Q_CC_BOR) |
| 1447 | # pragma option -w-inl |
| 1448 | # pragma option -w-aus |
| 1449 | # pragma warn -inl |
| 1450 | # pragma warn -pia |
| 1451 | # pragma warn -ccc |
| 1452 | # pragma warn -rch |
| 1453 | # pragma warn -sig |
| 1454 | # endif |
| 1455 | #endif |
| 1456 | |
| 1457 | #if !defined(QT_NO_EXCEPTIONS) |
| 1458 | # if !defined(Q_MOC_RUN) |
| 1459 | # if defined(Q_CC_GNU) && !defined(__cpp_exceptions) |
| 1460 | # define QT_NO_EXCEPTIONS |
| 1461 | # endif |
| 1462 | # elif defined(QT_BOOTSTRAPPED) |
| 1463 | # define QT_NO_EXCEPTIONS |
| 1464 | # endif |
| 1465 | #endif |
| 1466 | |
| 1467 | // libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346 |
| 1468 | #if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11) |
| 1469 | # define QT_COMPILER_HAS_LWG3346 |
| 1470 | #endif |
| 1471 | |
| 1472 | #if defined(__cplusplus) && __cplusplus >= 202002L // P0846 doesn't have a feature macro :/ |
| 1473 | # if !defined(Q_CC_MSVC_ONLY) || Q_CC_MSVC >= 1939 // claims C++20 support but lacks P0846 |
| 1474 | // 1939 is known to work |
| 1475 | // 1936 is known to fail |
| 1476 | # define QT_COMPILER_HAS_P0846 |
| 1477 | # endif |
| 1478 | #endif |
| 1479 | |
| 1480 | #ifdef QT_COMPILER_HAS_P0846 |
| 1481 | # define QT_ENABLE_P0846_SEMANTICS_FOR(func) |
| 1482 | #else |
| 1483 | class QT_CLASS_JUST_FOR_P0846_SIMULATION; |
| 1484 | # define QT_ENABLE_P0846_SEMANTICS_FOR(func) \ |
| 1485 | template <typename T> \ |
| 1486 | void func (QT_CLASS_JUST_FOR_P0846_SIMULATION *); \ |
| 1487 | /* end */ |
| 1488 | #endif // !P0846 |
| 1489 | |
| 1490 | #endif // __cplusplus |
| 1491 | |
| 1492 | #endif // QCOMPILERDETECTION_H |
| 1493 | |