Skip to content

Error Recovery

Günter Wirth edited this page Feb 6, 2022 · 10 revisions

To get meaningful SonarQube results your code should be syntactically correct code. The cxx plugin has error recovery on declaration level, but do not expect as much guidance as you can get from a C++ compiler.

Hint: In the case of incomplete scans, Detect and fix parsing errors gives advice on how to fix this.

Error recovery:

  • Syntax errors within a declaration are skipped, analysis is continued with next declaration.
  • For erroneous declarations the parser output the file, line number and closest identifier during analyzer run (e.g. sonar-runner).
  • Rule to detected skipped code do support you to find issues: Enable cxx:ParsingErrorRecovery(C++ skip parser error) in your Quality Profile.

Example:

01: int i=0;
02: 
03: void func1()
04: {
05:    i=1 //;
06: }
07:
08: void func2()
09: {
10:    i=2;
11: }

The parser will find a syntax error in line 5 (missing semicolon). This results in a syntax error in the func1 declaration. You will get the error message below. The parser ignores the whole declaration starting from line 3 and ending with line 6. The parser continues with analysis in line 7 (func2 is analyzed again).

15:54:45.567 WARN  - [example.cpp:3]: syntax error, skip 'func1'
Clone this wiki locally