summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qcompilerdetection.qdoc
blob: 191f26cc1fa748b3735a55918f7702293d37b265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \headerfile <QtCompilerDetection>
    \inmodule QtCore
    \title Compiler-specific Macro Definitions
    \ingroup funclists

    \brief The <QtCompilerDetection> header file includes various
    compiler-specific macros.

    The <QtCompilerDetection> header file provides a range of macros (Q_CC_*)
    that are defined if the application is compiled using the specified
    compiler. For example, the Q_CC_SUN macro is defined if the application is
    compiled using Forte Developer, or Sun Studio C++.

    The purpose of these macros is to enable programmers to add
    compiler-specific code to their application.
*/

/*!
    \macro Q_CC_SYM
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Digital Mars C/C++
    (used to be Symantec C++).
*/

/*!
    \macro Q_CC_MSVC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Microsoft Visual
    C/C++, Intel C++ for Windows.
*/

/*!
    \macro Q_CC_CLANG
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Clang.
*/

/*!
    \macro Q_CC_BOR
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Borland/Turbo C++.
*/

/*!
    \macro Q_CC_WAT
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Watcom C++.
*/

/*!
    \macro Q_CC_GNU
    \relates <QtCompilerDetection>

    Defined if the application is compiled using GNU Compiler Collection (GCC).
*/

/*!
    \macro Q_CC_COMEAU
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Comeau C++.
*/

/*!
    \macro Q_CC_EDG
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Edison Design Group
    C++.
*/

/*!
    \macro Q_CC_OC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using CenterLine C++.
*/

/*!
    \macro Q_CC_SUN
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Forte Developer, or
    Sun Studio C++.
*/

/*!
    \macro Q_CC_MIPS
    \relates <QtCompilerDetection>

    Defined if the application is compiled using MIPSpro C++.
*/

/*!
    \macro Q_CC_DEC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using DEC C++.
*/

/*!
    \macro Q_CC_HPACC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using HP aC++.
*/

/*!
    \macro Q_CC_USLC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using SCO OUDK and UDK.
*/

/*!
    \macro Q_CC_CDS
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Reliant C++.
*/

/*!
    \macro Q_CC_KAI
    \relates <QtCompilerDetection>

    Defined if the application is compiled using KAI C++.
*/

/*!
    \macro Q_CC_INTEL
    \relates <QtCompilerDetection>
    \obsolete

    This macro used to be defined if the application was compiled with the old
    Intel C++ compiler for Linux, macOS or Windows. The new oneAPI C++ compiler
    is just a build of Clang and therefore does not define this macro.

    \sa Q_CC_CLANG
*/

/*!
    \macro Q_CC_HIGHC
    \relates <QtCompilerDetection>

    Defined if the application is compiled using MetaWare High C/C++.
*/

/*!
    \macro Q_CC_PGI
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Portland Group C++.
*/

/*!
    \macro Q_CC_GHS
    \relates <QtCompilerDetection>

    Defined if the application is compiled using Green Hills
    Optimizing C++ Compilers.
*/

/*!
    \macro void Q_FALLTHROUGH()
    \relates <QtCompilerDetection>
    \since 5.8

    Can be used in switch statements at the end of case block to tell the compiler
    and other developers that the lack of a break statement is intentional.

    This is useful since a missing break statement is often a bug, and some
    compilers can be configured to emit warnings when one is not found.

    \sa Q_UNREACHABLE(), Q_UNREACHABLE_RETURN()
*/

/*!
    \macro Q_LIKELY(expr)
    \relates <QtCompilerDetection>
    \since 4.8

    \brief Hints to the compiler that the enclosed condition, \a expr, is
    likely to evaluate to \c true.

    Use of this macro can help the compiler to optimize the code.

    Example:

    \snippet code/src_corelib_global_qglobal.cpp qlikely

    \sa Q_UNLIKELY()
*/

/*!
    \macro Q_UNLIKELY(expr)
    \relates <QtCompilerDetection>
    \since 4.8

    \brief Hints to the compiler that the enclosed condition, \a expr, is
    likely to evaluate to \c false.

    Use of this macro can help the compiler to optimize the code.

    Example:

    \snippet code/src_corelib_global_qglobal.cpp qunlikely

    \sa Q_LIKELY()
*/

/*!
    \macro Q_CONSTINIT
    \relates <QtCompilerDetection>
    \since 6.4

    \brief Enforces constant initialization when supported by the compiler.

    If the compiler supports the C++20 \c{constinit} keyword, Clang's
    \c{[[clang::require_constant_initialization]]} or GCC's \c{__constinit},
    then this macro expands to the first one of these that is available,
    otherwise it expands to nothing.

    Variables marked as \c{constinit} cause a compile-error if their
    initialization would have to be performed at runtime.

    \note Constant-initialized variables may still have load-time impact if
    they have non-trivial destruction.

    For constants, you can use \c{constexpr} since C++11, but \c{constexpr}
    makes variables \c{const}, too, whereas \c{constinit} ensures constant
    initialization, but doesn't make the variable \c{const}:

    \table
    \header \li Keyword       \li Added \li immutable \li constant-initialized
    \row    \li \c{const}     \li C++98 \li yes       \li not required
    \row    \li \c{constexpr} \li C++11 \li yes       \li required
    \row    \li \c{constinit} \li C++20 \li no        \li required
    \endtable
*/

/*!
    \macro Q_DECL_EXPORT
    \relates <QtCompilerDetection>

    This macro marks a symbol for shared library export (see
     \l{sharedlibrary.html}{Creating Shared Libraries}).

    \sa Q_DECL_IMPORT
*/

/*!
    \macro Q_DECL_IMPORT
    \relates <QtCompilerDetection>

    This macro declares a symbol to be an import from a shared library (see
    \l{sharedlibrary.html}{Creating Shared Libraries}).

    \sa Q_DECL_EXPORT
*/

/*!
    \macro Q_DECL_CONSTEXPR
    \relates <QtCompilerDetection>
    \deprecated [6.4] Use the \c constexpr keyword instead.

    This macro can be used to declare variable that should be constructed at compile-time,
    or an inline function that can be computed at compile-time.

    \sa Q_DECL_RELAXED_CONSTEXPR
*/

/*!
    \macro Q_DECL_RELAXED_CONSTEXPR
    \relates <QtCompilerDetection>
    \deprecated [6.4] Use the \c constexpr keyword instead.

    This macro can be used to declare an inline function that can be computed
    at compile-time according to the relaxed rules from C++14.

    \sa Q_DECL_CONSTEXPR
*/

/*!
    \macro Q_DECL_NOTHROW
    \relates <QtCompilerDetection>
    \since 5.0
    \deprecated [6.4] Use the \c noexcept keyword instead.

    This macro marks a function as never throwing, under no
    circumstances. If the function does nevertheless throw, the
    behavior is undefined.

    \sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR()
*/

/*!
    \macro Q_DECL_NOEXCEPT
    \relates <QtCompilerDetection>
    \since 5.0
    \deprecated [6.4] Use the \c noexcept keyword instead.

    This macro marks a function as never throwing. If the function
    does nevertheless throw, the behavior is defined:
    std::terminate() is called.


    \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR()
*/

/*!
    \macro Q_DECL_NOEXCEPT_EXPR(x)
    \relates <QtCompilerDetection>
    \since 5.0
    \deprecated [6.4] Use the \c noexcept keyword instead.

    This macro marks a function as non-throwing if \a x is \c true. If
    the function does nevertheless throw, the behavior is defined:
    std::terminate() is called.


    \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT
*/

/*!
    \macro Q_DECL_OVERRIDE
    \since 5.0
    \deprecated
    \relates <QtCompilerDetection>

    This macro can be used to declare an overriding virtual
    function. Use of this markup will allow the compiler to generate
    an error if the overriding virtual function does not in fact
    override anything.

    It expands to "override".

    The macro goes at the end of the function, usually after the
    \c{const}, if any:
    \snippet code/src_corelib_global_qglobal.cpp qdecloverride

    \sa Q_DECL_FINAL
*/

/*!
    \macro Q_DECL_FINAL
    \since 5.0
    \deprecated
    \relates <QtCompilerDetection>

    This macro can be used to declare an overriding virtual or a class
    as "final", with Java semantics. Further-derived classes can then
    no longer override this virtual function, or inherit from this
    class, respectively.

    It expands to "final".

    The macro goes at the end of the function, usually after the
    \c{const}, if any:
    \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-1

    For classes, it goes in front of the \c{:} in the class
    definition, if any:
    \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-2

    \sa Q_DECL_OVERRIDE
*/

/*!
    \macro const char* Q_FUNC_INFO()
    \relates <QtCompilerDetection>

    Expands to a string that describe the function the macro resides in. How this string looks
    more specifically is compiler dependent. With GNU GCC it is typically the function signature,
    while with other compilers it might be the line and column number.

    Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:

    \snippet code/src_corelib_global_qglobal.cpp 22

    when instantiated with the integer type, will with the GCC compiler produce:

    \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}

    If this macro is used outside a function, the behavior is undefined.
*/

/*!
    \macro Q_NODISCARD_CTOR
    \relates <QtCompilerDetection>
    \since 6.6

    \brief Expands to \c{[[nodiscard]]} on compilers that accept it on constructors.

    Otherwise it expands to nothing.

    Constructors marked as Q_NODISCARD_CTOR cause a compiler warning if a call
    site doesn't use the resulting object.

    This macro is exists solely to prevent warnings on compilers that don't
    implement the feature. If your supported platforms all allow \c{[[nodiscard]]}
    on constructors, we strongly recommend you use the C++ attribute directly instead
    of this macro.

    \sa Q_NODISCARD_CTOR_X
*/

/*!
    \macro Q_NODISCARD_X(message)
    \macro Q_NODISCARD_CTOR_X(message)
    \relates <QtCompilerDetection>
    \since 6.7

    \brief Expand to \c{[[nodiscard(message)]]} on compilers that support the feature.

    Otherwise they expand to \c {[[nodiscard]]} and Q_NODISCARD_CTOR, respectively.

    \sa Q_NODISCARD_CTOR
*/