Skip to content

Predefined Macros

Günter Wirth edited this page Jan 23, 2023 · 11 revisions

The cxx plugin already defines some macros to be functional. For most build environments, these predefined macros are not sufficient. Please check your build environment and project settings to see which additional macros you need to define with sonar.cxx.defines.

Some links to common build environments and their Predefined Macros.

Predefined macros of the cxx plugin:

Macro Value Comment
__FILE__ "file" always the same dummy value
__LINE__ 1 always the same dummy value
__DATE__ "??? ?? ????" indicates 'date unknown'
__TIME__ "??:??:??" indicates 'time unknown'
__STDC__ 1 1 means that this compiler conforms to ISO Standard C
__STDC_HOSTED__ 1 This macro is defined, with value 1, if the compiler’s target is a hosted environment. A hosted environment has the complete facilities of the standard C library available.
__cplusplus 201402L language standard C++14
__has_builtin(x) 0 defines Feature Checking Macro
__has_feature(x) 0 defines Feature Checking Macro
__has_extension(x) 0 defines Feature Checking Macro
__has_cpp_attribute(x) 0 defines Feature Checking Macro
__has_c_attribute(x) 0 defines Feature Checking Macro
__has_attribute(x) 0 defines Feature Checking Macro
__has_declspec_attribute(x) 0 defines Feature Checking Macro
__is_identifier(x) 1 defines Feature Checking Macro
__has_warning(x) 0 defines Feature Checking Macro

Hint: With sonar.cxx.defines and sonar.cxx.forceIncludes the predefined macro values can be redefined.


Automatically extract macros from the build system

The cxx plugin can also automatically extract macros from MSBuild .LOG files or JSON Compilation Databases. More information can be found at the respective parameter sonar.cxx.msbuild.reportPaths or sonar.cxx.jsonCompilationDatabase.

Clone this wiki locally