- Qt 6.9
- Qt Core
- <QtCompilerDetection> - Compiler-specific Macro Definitions
- Qt 6.9.3 Reference Documentation

# <QtCompilerDetection> - Compiler-specific Macro Definitions

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

Header: | `#include <QtCompilerDetection>`

- Deprecated members

## Macros

`(since 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
`(since 6.9)` | Q_CONSTEXPR_DTOR
`(since 6.4)` | Q_CONSTINIT
`(since 6.9)` | Q_DECL_CONSTEXPR_DTOR
`(since 6.9)` | Q_DECL_EQ_DELETE_X(reason)
| Q_DECL_EXPORT
| Q_DECL_IMPORT
void | Q_FALLTHROUGH()
const char* | Q_FUNC_INFO()
| Q_LIKELY(expr)
`(since 6.9)` | Q_LIKELY_BRANCH
`(since 6.6)` | Q_NODISCARD_CTOR
`(since 6.7)` | Q_NODISCARD_CTOR_X(message)
`(since 6.7)` | Q_NODISCARD_X(message)
| Q_UNLIKELY(expr)
`(since 6.9)` | Q_UNLIKELY_BRANCH

## Detailed Description

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 Documentation

### `[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, respectively.

This function was introduced in Qt 6.7.

See also Q_NODISCARD_CTOR.

### Q_CC_BOR

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

### Q_CC_CDS

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

### Q_CC_CLANG

Defined if the application is compiled using Clang.

### Q_CC_COMEAU

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

### Q_CC_DEC

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

### Q_CC_EDG

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

### Q_CC_GHS

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

### Q_CC_GNU

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

### Q_CC_HIGHC

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

### Q_CC_HPACC

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

### Q_CC_KAI

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

### Q_CC_MIPS

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

### Q_CC_MSVC

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

### Q_CC_OC

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

### Q_CC_PGI

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

### Q_CC_SUN

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

### Q_CC_SYM

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

### Q_CC_USLC

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

### Q_CC_WAT

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

### `[since 6.9]` Q_CONSTEXPR_DTOR

Expands to `constexpr` on compilers that support C++20, where `__cpp_constexpr` has a value greater than or equal to `201907L`. Otherwise, it expands to `const`.

Use this macro to declare a variable that can be constructed at compile-time in C++20 or later.

This macro was introduced in Qt 6.9.

See also Q_DECL_CONSTEXPR_DTOR.

### `[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.

Note: 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 | Added | 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.

### `[since 6.9]` Q_DECL_CONSTEXPR_DTOR

Expands to `constexpr` on compilers that support C++20, where `__cpp_constexpr` has a value greater than or equal to `201907L`. Otherwise, it expands to `inline`.

Use this macro to declare a destructor that can be computed at compile-time in C++20 or later.

This macro was introduced in Qt 6.9.

See also Q_CONSTEXPR_DTOR.

### `[since 6.9]` Q_DECL_EQ_DELETE_X(reason)

Expands to `= delete(reason)` on compilers that support C++26, where `__cpp_deleted_function` has a value greater than or equal to `202403L`. Otherwise, it expands to `= delete`.

Use this macro to declare a deleted function and also supply an error message (the reason) to the user in case the function gets used (explaining why the function was deleted).

This macro was introduced in Qt 6.9.

### Q_DECL_EXPORT

This macro marks a symbol for shared library export (see Creating Shared Libraries).

See also Q_DECL_IMPORT.

### Q_DECL_IMPORT

This macro declares a symbol to be an import from a shared library (see Creating Shared Libraries).

See also Q_DECL_EXPORT.

### void Q_FALLTHROUGH()

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.

See also Q_UNREACHABLE() and Q_UNREACHABLE_RETURN().

### const char*Q_FUNC_INFO()

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:

     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.

### Q_LIKELY(expr)

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.

Example:

         // the condition inside the "if" will be successful most of the times
         for (int i = 1; i <= 365; i++) {
             if (Q_LIKELY(isWorkingDay(i))) {
                 ...
             }
             ...
         }

See also Q_UNLIKELY(), Q_LIKELY_BRANCH, and Q_UNLIKELY_BRANCH.

### `[since 6.9]` Q_LIKELY_BRANCH

Hints to the compiler that the following block is likely to be executed.

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

It is defined as the C++20 attribute `[[likely]]`, and is a no-op on compilers that don't support it.

This macro was introduced in Qt 6.9.

See also Q_LIKELY(), Q_UNLIKELY(), and Q_UNLIKELY_BRANCH.

### `[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.

See also Q_NODISCARD_CTOR_X.

### Q_UNLIKELY(expr)

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.

Example:

     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;
     }

See also Q_LIKELY(), Q_LIKELY_BRANCH, and Q_UNLIKELY_BRANCH.

### `[since 6.9]` Q_UNLIKELY_BRANCH

Hints to the compiler that the following block is unlikely to be executed.

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

It is defined as the C++20 attribute `[[unlikely]]`, and is a no-op on compilers that don't support it.

This macro was introduced in Qt 6.9.

See also Q_LIKELY(), Q_UNLIKELY(), and Q_LIKELY_BRANCH.