The <QtCompilerDetection> header file includes various compiler-specific macros. 更多...
头: | #include <QtCompilerDetection> |
(从 6.7 起)
|
|
Q_CC_BOR | |
Q_CC_CDS | |
Q_CC_CLANG | |
Q_CC_COMEAU | |
Q_CC_DEC | |
Q_CC_EDG | |
Q_CC_GHS | |
Q_CC_GNU | |
Q_CC_HIGHC | |
Q_CC_HPACC | |
Q_CC_KAI | |
Q_CC_MIPS | |
Q_CC_MSVC | |
Q_CC_OC | |
Q_CC_PGI | |
Q_CC_SUN | |
Q_CC_SYM | |
Q_CC_USLC | |
Q_CC_WAT | |
(从 6.4 起)
|
Q_CONSTINIT |
Q_DECL_EXPORT | |
Q_DECL_IMPORT | |
void | Q_FALLTHROUGH |
const char* | Q_FUNC_INFO |
Q_LIKELY ( expr ) | |
(从 6.6 起)
|
Q_NODISCARD_CTOR |
(从 6.7 起)
|
Q_NODISCARD_CTOR_X ( message ) |
(从 6.7 起)
|
Q_NODISCARD_X ( message ) |
Q_UNLIKELY ( expr ) |
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.
[since 6.7]
Q_NODISCARD_CTOR_X
(
message
)
[since 6.7]
Q_NODISCARD_X
(
message
)
Expand to
[[nodiscard(message)]]
on compilers that support the feature.
Otherwise they expand to
[[nodiscard]]
and
Q_NODISCARD_CTOR
,分别。
该函数在 Qt 6.7 引入。
另请参阅 Q_NODISCARD_CTOR .
Defined if the application is compiled using Borland/Turbo C++.
Defined if the application is compiled using Reliant C++.
Defined if the application is compiled using Clang.
Defined if the application is compiled using Comeau C++.
Defined if the application is compiled using DEC C++.
Defined if the application is compiled using Edison Design Group C++.
Defined if the application is compiled using Green Hills Optimizing C++ Compilers.
Defined if the application is compiled using GNU Compiler Collection (GCC).
Defined if the application is compiled using MetaWare High C/C++.
Defined if the application is compiled using HP aC++.
Defined if the application is compiled using KAI C++.
Defined if the application is compiled using MIPSpro C++.
Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.
Defined if the application is compiled using CenterLine C++.
Defined if the application is compiled using Portland Group C++.
Defined if the application is compiled using Forte Developer, or Sun Studio C++.
Defined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++).
Defined if the application is compiled using SCO OUDK and UDK.
Defined if the application is compiled using Watcom C++.
[since 6.4]
Q_CONSTINIT
Enforces constant initialization when supported by the compiler.
If the compiler supports the C++20
constinit
keyword, Clang's
[[clang::require_constant_initialization]]
or GCC's
__constinit
, then this macro expands to the first one of these that is available, otherwise it expands to nothing.
Variables marked as
constinit
cause a compile-error if their initialization would have to be performed at runtime.
注意: Constant-initialized variables may still have load-time impact if they have non-trivial destruction.
For constants, you can use
constexpr
since C++11, but
constexpr
makes variables
const
, too, whereas
constinit
ensures constant initialization, but doesn't make the variable
const
:
Keyword | 添加 | immutable | constant-initialized |
---|---|---|---|
const
|
C++98 | yes | not required |
constexpr
|
C++11 | yes | required |
constinit
|
C++20 | no | required |
This macro was introduced in Qt 6.4.
This macro marks a symbol for shared library export (see 创建共享库 ).
另请参阅 Q_DECL_IMPORT .
This macro declares a symbol to be an import from a shared library (see 创建共享库 ).
另请参阅 Q_DECL_EXPORT .
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.
另请参阅 Q_UNREACHABLE () 和 Q_UNREACHABLE_RETURN ().
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 ()。例如,此函数:
template<typename TInputType> const TInputType &myMin(const TInputType &value1, const TInputType &value2) { qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; if(value1 < value2) return value1; else return value2; }
when instantiated with the integer type, will with the GCC compiler produce:
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.
Hints to the compiler that the enclosed condition,
expr
, is likely to evaluate to
true
.
Use of this macro can help the compiler to optimize the code.
范例:
// the condition inside the "if" will be successful most of the times for (int i = 1; i <= 365; i++) { if (Q_LIKELY(isWorkingDay(i))) { ... } ... }
另请参阅 Q_UNLIKELY ().
[since 6.6]
Q_NODISCARD_CTOR
Expands to
[[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
[[nodiscard]]
on constructors, we strongly recommend you use the C++ attribute directly instead of this macro.
This macro was introduced in Qt 6.6.
另请参阅 Q_NODISCARD_CTOR_X .
[since 6.7]
Q_NODISCARD_CTOR_X
(
message
)
该宏在 Qt 6.7 引入。
[since 6.7]
Q_NODISCARD_X
(
message
)
该宏在 Qt 6.7 引入。
Hints to the compiler that the enclosed condition,
expr
, is likely to evaluate to
false
.
Use of this macro can help the compiler to optimize the code.
范例:
bool readConfiguration(const QFile &file) { // We expect to be asked to read an existing file if (Q_UNLIKELY(!file.exists())) { qWarning() << "File not found"; return false; } ... return true; }
另请参阅 Q_LIKELY ().