Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcompilerdetection.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \headerfile <QtCompilerDetection>
6 \inmodule QtCore
7 \title Compiler-specific Macro Definitions
8 \ingroup funclists
9
10 \brief The <QtCompilerDetection> header file includes various
11 compiler-specific macros.
12
13 The <QtCompilerDetection> header file provides a range of macros (Q_CC_*)
14 that are defined if the application is compiled using the specified
15 compiler. For example, the Q_CC_SUN macro is defined if the application is
16 compiled using Forte Developer, or Sun Studio C++.
17
18 The purpose of these macros is to enable programmers to add
19 compiler-specific code to their application.
20*/
21
22/*!
23 \macro Q_CC_SYM
24 \relates <QtCompilerDetection>
25
26 Defined if the application is compiled using Digital Mars C/C++
27 (used to be Symantec C++).
28*/
29
30/*!
31 \macro Q_CC_MSVC
32 \relates <QtCompilerDetection>
33
34 Defined if the application is compiled using Microsoft Visual
35 C/C++, Intel C++ for Windows.
36*/
37
38/*!
39 \macro Q_CC_CLANG
40 \relates <QtCompilerDetection>
41
42 Defined if the application is compiled using Clang.
43*/
44
45/*!
46 \macro Q_CC_BOR
47 \relates <QtCompilerDetection>
48
49 Defined if the application is compiled using Borland/Turbo C++.
50*/
51
52/*!
53 \macro Q_CC_WAT
54 \relates <QtCompilerDetection>
55
56 Defined if the application is compiled using Watcom C++.
57*/
58
59/*!
60 \macro Q_CC_GNU
61 \relates <QtCompilerDetection>
62
63 Defined if the application is compiled using GNU Compiler Collection (GCC).
64*/
65
66/*!
67 \macro Q_CC_COMEAU
68 \relates <QtCompilerDetection>
69
70 Defined if the application is compiled using Comeau C++.
71*/
72
73/*!
74 \macro Q_CC_EDG
75 \relates <QtCompilerDetection>
76
77 Defined if the application is compiled using Edison Design Group
78 C++.
79*/
80
81/*!
82 \macro Q_CC_OC
83 \relates <QtCompilerDetection>
84
85 Defined if the application is compiled using CenterLine C++.
86*/
87
88/*!
89 \macro Q_CC_SUN
90 \relates <QtCompilerDetection>
91
92 Defined if the application is compiled using Forte Developer, or
93 Sun Studio C++.
94*/
95
96/*!
97 \macro Q_CC_MIPS
98 \relates <QtCompilerDetection>
99
100 Defined if the application is compiled using MIPSpro C++.
101*/
102
103/*!
104 \macro Q_CC_DEC
105 \relates <QtCompilerDetection>
106
107 Defined if the application is compiled using DEC C++.
108*/
109
110/*!
111 \macro Q_CC_HPACC
112 \relates <QtCompilerDetection>
113
114 Defined if the application is compiled using HP aC++.
115*/
116
117/*!
118 \macro Q_CC_USLC
119 \relates <QtCompilerDetection>
120
121 Defined if the application is compiled using SCO OUDK and UDK.
122*/
123
124/*!
125 \macro Q_CC_CDS
126 \relates <QtCompilerDetection>
127
128 Defined if the application is compiled using Reliant C++.
129*/
130
131/*!
132 \macro Q_CC_KAI
133 \relates <QtCompilerDetection>
134
135 Defined if the application is compiled using KAI C++.
136*/
137
138/*!
139 \macro Q_CC_INTEL
140 \relates <QtCompilerDetection>
141 \obsolete
142
143 This macro used to be defined if the application was compiled with the old
144 Intel C++ compiler for Linux, macOS or Windows. The new oneAPI C++ compiler
145 is just a build of Clang and therefore does not define this macro.
146
147 \sa Q_CC_CLANG
148*/
149
150/*!
151 \macro Q_CC_HIGHC
152 \relates <QtCompilerDetection>
153
154 Defined if the application is compiled using MetaWare High C/C++.
155*/
156
157/*!
158 \macro Q_CC_PGI
159 \relates <QtCompilerDetection>
160
161 Defined if the application is compiled using Portland Group C++.
162*/
163
164/*!
165 \macro Q_CC_GHS
166 \relates <QtCompilerDetection>
167
168 Defined if the application is compiled using Green Hills
169 Optimizing C++ Compilers.
170*/
171
172/*!
173 \macro void Q_FALLTHROUGH()
174 \relates <QtCompilerDetection>
175 \since 5.8
176
177 Can be used in switch statements at the end of case block to tell the compiler
178 and other developers that the lack of a break statement is intentional.
179
180 This is useful since a missing break statement is often a bug, and some
181 compilers can be configured to emit warnings when one is not found.
182
183 \sa Q_UNREACHABLE(), Q_UNREACHABLE_RETURN()
184*/
185
186/*!
187 \macro Q_LIKELY(expr)
188 \relates <QtCompilerDetection>
189 \since 4.8
190
191 \brief Hints to the compiler that the enclosed condition, \a expr, is
192 likely to evaluate to \c true.
193
194 Use of this macro can help the compiler to optimize the code.
195
196 Example:
197
198 \snippet code/src_corelib_global_qglobal.cpp qlikely
199
200 \sa Q_UNLIKELY()
201*/
202
203/*!
204 \macro Q_UNLIKELY(expr)
205 \relates <QtCompilerDetection>
206 \since 4.8
207
208 \brief Hints to the compiler that the enclosed condition, \a expr, is
209 likely to evaluate to \c false.
210
211 Use of this macro can help the compiler to optimize the code.
212
213 Example:
214
215 \snippet code/src_corelib_global_qglobal.cpp qunlikely
216
217 \sa Q_LIKELY()
218*/
219
220/*!
221 \macro Q_CONSTINIT
222 \relates <QtCompilerDetection>
223 \since 6.4
224
225 \brief Enforces constant initialization when supported by the compiler.
226
227 If the compiler supports the C++20 \c{constinit} keyword, Clang's
228 \c{[[clang::require_constant_initialization]]} or GCC's \c{__constinit},
229 then this macro expands to the first one of these that is available,
230 otherwise it expands to nothing.
231
232 Variables marked as \c{constinit} cause a compile-error if their
233 initialization would have to be performed at runtime.
234
235 \note Constant-initialized variables may still have load-time impact if
236 they have non-trivial destruction.
237
238 For constants, you can use \c{constexpr} since C++11, but \c{constexpr}
239 makes variables \c{const}, too, whereas \c{constinit} ensures constant
240 initialization, but doesn't make the variable \c{const}:
241
242 \table
243 \header \li Keyword \li Added \li immutable \li constant-initialized
244 \row \li \c{const} \li C++98 \li yes \li not required
245 \row \li \c{constexpr} \li C++11 \li yes \li required
246 \row \li \c{constinit} \li C++20 \li no \li required
247 \endtable
248*/
249
250/*!
251 \macro Q_DECL_EXPORT
252 \relates <QtCompilerDetection>
253
254 This macro marks a symbol for shared library export (see
255 \l{sharedlibrary.html}{Creating Shared Libraries}).
256
257 \sa Q_DECL_IMPORT
258*/
259
260/*!
261 \macro Q_DECL_IMPORT
262 \relates <QtCompilerDetection>
263
264 This macro declares a symbol to be an import from a shared library (see
265 \l{sharedlibrary.html}{Creating Shared Libraries}).
266
267 \sa Q_DECL_EXPORT
268*/
269
270/*!
271 \macro Q_DECL_CONSTEXPR
272 \relates <QtCompilerDetection>
273 \deprecated [6.4] Use the \c constexpr keyword instead.
274
275 This macro can be used to declare variable that should be constructed at compile-time,
276 or an inline function that can be computed at compile-time.
277
278 \sa Q_DECL_RELAXED_CONSTEXPR
279*/
280
281/*!
282 \macro Q_DECL_RELAXED_CONSTEXPR
283 \relates <QtCompilerDetection>
284 \deprecated [6.4] Use the \c constexpr keyword instead.
285
286 This macro can be used to declare an inline function that can be computed
287 at compile-time according to the relaxed rules from C++14.
288
289 \sa Q_DECL_CONSTEXPR
290*/
291
292/*!
293 \macro Q_DECL_NOTHROW
294 \relates <QtCompilerDetection>
295 \since 5.0
296 \deprecated [6.4] Use the \c noexcept keyword instead.
297
298 This macro marks a function as never throwing, under no
299 circumstances. If the function does nevertheless throw, the
300 behavior is undefined.
301
302 \sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR()
303*/
304
305/*!
306 \macro Q_DECL_NOEXCEPT
307 \relates <QtCompilerDetection>
308 \since 5.0
309 \deprecated [6.4] Use the \c noexcept keyword instead.
310
311 This macro marks a function as never throwing. If the function
312 does nevertheless throw, the behavior is defined:
313 std::terminate() is called.
314
315
316 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR()
317*/
318
319/*!
320 \macro Q_DECL_NOEXCEPT_EXPR(x)
321 \relates <QtCompilerDetection>
322 \since 5.0
323 \deprecated [6.4] Use the \c noexcept keyword instead.
324
325 This macro marks a function as non-throwing if \a x is \c true. If
326 the function does nevertheless throw, the behavior is defined:
327 std::terminate() is called.
328
329
330 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT
331*/
332
333/*!
334 \macro Q_DECL_OVERRIDE
335 \since 5.0
336 \deprecated
337 \relates <QtCompilerDetection>
338
339 This macro can be used to declare an overriding virtual
340 function. Use of this markup will allow the compiler to generate
341 an error if the overriding virtual function does not in fact
342 override anything.
343
344 It expands to "override".
345
346 The macro goes at the end of the function, usually after the
347 \c{const}, if any:
348 \snippet code/src_corelib_global_qglobal.cpp qdecloverride
349
350 \sa Q_DECL_FINAL
351*/
352
353/*!
354 \macro Q_DECL_FINAL
355 \since 5.0
356 \deprecated
357 \relates <QtCompilerDetection>
358
359 This macro can be used to declare an overriding virtual or a class
360 as "final", with Java semantics. Further-derived classes can then
361 no longer override this virtual function, or inherit from this
362 class, respectively.
363
364 It expands to "final".
365
366 The macro goes at the end of the function, usually after the
367 \c{const}, if any:
368 \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-1
369
370 For classes, it goes in front of the \c{:} in the class
371 definition, if any:
372 \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-2
373
374 \sa Q_DECL_OVERRIDE
375*/
376
377/*!
378 \macro const char* Q_FUNC_INFO()
379 \relates <QtCompilerDetection>
380
381 Expands to a string that describe the function the macro resides in. How this string looks
382 more specifically is compiler dependent. With GNU GCC it is typically the function signature,
383 while with other compilers it might be the line and column number.
384
385 Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
386
387 \snippet code/src_corelib_global_qglobal.cpp 22
388
389 when instantiated with the integer type, will with the GCC compiler produce:
390
391 \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
392
393 If this macro is used outside a function, the behavior is undefined.
394*/
395
396/*!
397 \macro Q_NODISCARD_CTOR
398 \relates <QtCompilerDetection>
399 \since 6.6
400
401 \brief Expands to \c{[[nodiscard]]} on compilers that accept it on constructors.
402
403 Otherwise it expands to nothing.
404
405 Constructors marked as Q_NODISCARD_CTOR cause a compiler warning if a call
406 site doesn't use the resulting object.
407
408 This macro is exists solely to prevent warnings on compilers that don't
409 implement the feature. If your supported platforms all allow \c{[[nodiscard]]}
410 on constructors, we strongly recommend you use the C++ attribute directly instead
411 of this macro.
412
413 \sa Q_NODISCARD_CTOR_X
414*/
415
416/*!
417 \macro Q_NODISCARD_X(message)
418 \macro Q_NODISCARD_CTOR_X(message)
419 \relates <QtCompilerDetection>
420 \since 6.7
421
422 \brief Expand to \c{[[nodiscard(message)]]} on compilers that support the feature.
423
424 Otherwise they expand to \c {[[nodiscard]]} and Q_NODISCARD_CTOR, respectively.
425
426 \sa Q_NODISCARD_CTOR
427*/