clion-cppcheck
clion-cppcheck copied to clipboard
Override errors with virtual functions not shown
Environment
- Operating System (e.g. Ubuntu 16.04 x64): win7
- IDE Version (e.g. CLion 2016.3.2): clion 2016.2.3
- Cppcheck executable version (
cppcheck --version
): 1.8.4 - Cppcheck plugin version: .12.0
- Exact strings used in cppcheck plugin options:
- cppcheck options: --enable=all --language=c++ --std=c++11
Expected behaviour
Report all errors from cppcheck.
Actual behaviour
Errors about missing c++11 override
are not shown.
Steps to reproduce the behaviour
- Create files
- file
a.h
:
class a {
public:
virtual int testfunc()=0;
};
class b : public a {
public:
virtual int testfunc() {
int i = 0;
return i;
};
};
- file
c.h
:
#include "a.h"
class c : public a {
public:
virtual int testfunc() {
int i = 0;
return i;
};
};
- Run normal code inspection.
- On
a.h
the override error is shown. Onc.h
the error is not shown.
Analysis
Look at cppcheck
Run cppcheck
manually on a.h
:
[a.h:3] -> [a.h:8]: (style) The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier.
Run cppcheck
manually on c.h
:
[a.h:3] -> [a.h:8]: (style) The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier. [a.h:3] -> [c.h:4]: (style) The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier.
Result: cppcheck
recognizes the error. -> somehow filtered by the plugin
Look into plugin
Problem: Pattern only filters first file name. Second file name is not analyzed.
[a.h:3] -> [c.h:4]: (style) The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier.
Means a.h
is detected and filtered by line:
https://github.com/johnthagen/clion-cppcheck/blob/master/src/com/github/johnthagen/cppcheck/CppcheckInspection.java#L140
Solution
Extend pattern/regex to get second file name and filter against this file.
Why no fix or pr?
I am not good at regex writing :(.
This shows the limitation of regex handling. A better long term solution would be to drop regex in favor of XML parsing (#9).
CC @fastasturtle, a past contributor, for any thoughts
We are now parsing the --xml
output instead of using regular expression on the text output. I will test this and see if the results are as expected.
I tried this with the '--xml' changes and I get the following
a.h - at line 8:
Cppcheck: (style) missingOverride: The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier.
c.h - at line 4:
Cppcheck: (style) missingOverride: The function 'testfunc' overrides a function in a base class but is not marked with a 'override' specifier.
Looks like this is fixed with the upcoming 1.6.0 release.