Skip to content

sonar.cxx.vc.regex

Günter Wirth edited this page Nov 15, 2024 · 4 revisions

To read sonar.cxx.vc.reportPaths a default sonar.cxx.vc.regex is already set, this can be customized if required. A regular expression can be defined to read the text. The regular expressions follow the Java convention.

Depending on the Visual Studio version and the compiler options, the format of the warnings differs slightly:

Visual Studio Version sonar.cxx.vc.regex
Visual Studio 2010-2015 (.*>)?(?<file>.*)\((?<line>\d+)\)\x20:\x20warning\x20(?<id>C\d+):(?<message>.*)
Visual Studio 2017 (.*>)?(?<file>.*)\((?<line>\d+)\):\x20warning\x20(?<id>C\d+):\x20(?<message>.*)
Visual Studio 2019-2022 (default) (?>[^>]*+>)?(?<file>(?>[^\\]{1,260}\\)*[^\\]{1,260})\((?<line>\d{1,5})\)\x20?:\x20warning\x20(?<id>C\d{4,5}):\x20?(?<message>.*)

Hint: You have to escape the backslash (\-> \\) for the regex parameter in the configuration file!

The format of the build log looks different for parallel project builds (e.g. MSBuild options /maxcpucount:xx) and the regular expression has to consider this.

log type example
single process D:\Sample\File1.cpp(414,41): warning ...
multiple processes 1>D:\Sample\File1.cpp(414,41): warning ...

For the assignment of the individual parameters named-capturing groups are used. A capturing group (...) can also be assigned a "name", a named-capturing group e.g. (?<file>.*): The following named-capturing groups are defined:

named-capturing group description
<file> filename part of the issue
<line> line number of the issue
<column> column number of the issue
<id> rule id of the issue
<message> message text of the issue

Sample:

If the following regular expression is defined

sonar.cxx.vc.regex=(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)\\x20\\[(?<id>.*)\\]

and the sensor reads this text

src/zipmanager.cpp:141:10: warning: conversion to 'unsigned char' from 'unsigned int' may alter its value [-Wconversion]

then the text is split up as follows:

pattern description match
(?<file>.*): filename part of the issue src/zipmanager.cpp
(?<line>[0-9]+): line number of the issue 141
[0-9]+:\x20warning:\x20 ignoring column and warning text
(?<message>.*)\x20 message text of the issue conversion to 'unsigned char' from 'unsigned int' may alter its value
\[(?<id>.*)\] rule id of the issue -Wconversion
Clone this wiki locally