clion-cppcheck icon indicating copy to clipboard operation
clion-cppcheck copied to clipboard

Override errors with virtual functions not shown

Open Rotzbua opened this issue 6 years ago • 3 comments

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

  1. 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;
		};
};
  1. Run normal code inspection.
  2. On a.h the override error is shown. On c.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 :(.

Rotzbua avatar Jul 29 '18 00:07 Rotzbua

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

johnthagen avatar Jul 29 '18 12:07 johnthagen

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.

firewave avatar Nov 21 '20 20:11 firewave

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.

firewave avatar Dec 23 '20 10:12 firewave