using namespace std;
class MyClass : public std::basic_streambuf<char>
{
public :
int_type overflow(int_type c = traits_type::eof());
};</char>
CppCheck Does not detects that the function 'overflow' is virtual in the std::basic_streambuf class and
does not hits the predefined rule which is
"The function '$symbol' overrides a function in a base class but is not marked with a 'override' specifier."
It Happens because the class that is inherited is in a lib function and the Code File does not exits in the folder path specified.
Can any one tell me what should I do to hit the Rule.
Any help would be appreciated..
Note : The Corresponding Function is in the checkclass.cpp - void CheckClass::checkOverride()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know if I can help you immediately with this. there is no good quick answer.
If you want this check to work today then I am afraid my recommendation is to use another tool. I believe there are a few compilers and tools that will warn about missing override. I can't recommend a specific one. But it seems that gcc/clang/msvc/clang-tidy has this warning.
I really do not recommend that system headers are included in Cppcheck but you could try to see what happens if you use -I /usr/include or some such.
A proper fix in Cppcheck would be nice. However;
- Putting this info in the cfg files would be very labour intensive
- I do not want that system headers are included
We could create some kind of method that will automatically parse out the type declarations from the system headers and put it in some kind of database.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The main problem (besides performance) in checking header files is setting all the builtin system specific defines necessary for the code to make sense. Since we don't automatically add these magic defines in cppcheck (I believe there was a patch to do this) we could run system headers through the system cpp before simplecpp. Unfortunately this will only work if the platform type is native.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Daniel Marjamäki Thanks for your quick feedback.
I tried using the -I option but still the rule did not got hit.
The Following code does produces the desired output That the
"The function 'f' overrides a function in a base class but is not marked with a 'override'
I have searched a bit, but it seems that Visual Studio does not have such a warning. It can warn when override is specified but now allowed. But not if there is an override missing.
If someone finds information how to warn about missing override in Visual Studio i would be interested also.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Consider the following Code snippet:
include <iostream></iostream>
using namespace std;
class MyClass : public std::basic_streambuf<char>
{
public :
int_type overflow(int_type c = traits_type::eof());
};</char>
CppCheck Does not detects that the function 'overflow' is virtual in the std::basic_streambuf class and
does not hits the predefined rule which is
"The function '$symbol' overrides a function in a base class but is not marked with a 'override' specifier."
It Happens because the class that is inherited is in a lib function and the Code File does not exits in the folder path specified.
Can any one tell me what should I do to hit the Rule.
Any help would be appreciated..
Note : The Corresponding Function is in the checkclass.cpp - void CheckClass::checkOverride()
I don't know if I can help you immediately with this. there is no good quick answer.
If you want this check to work today then I am afraid my recommendation is to use another tool. I believe there are a few compilers and tools that will warn about missing override. I can't recommend a specific one. But it seems that gcc/clang/msvc/clang-tidy has this warning.
I really do not recommend that system headers are included in Cppcheck but you could try to see what happens if you use
-I /usr/include
or some such.A proper fix in Cppcheck would be nice. However;
- Putting this info in the cfg files would be very labour intensive
- I do not want that system headers are included
We could create some kind of method that will automatically parse out the type declarations from the system headers and put it in some kind of database.
The main problem (besides performance) in checking header files is setting all the builtin system specific defines necessary for the code to make sense. Since we don't automatically add these magic defines in cppcheck (I believe there was a patch to do this) we could run system headers through the system cpp before simplecpp. Unfortunately this will only work if the platform type is native.
@Daniel Marjamäki Thanks for your quick feedback.
I tried using the -I option but still the rule did not got hit.
The Following code does produces the desired output That the
"The function 'f' overrides a function in a base class but is not marked with a 'override'
Wonder why the below does not works tried by giving the include dir paths to it as well but no Luck.
gcc:
clang-tidy:
I gave the Following command and it did not work as you gave:
so use a compiler or other tool. for now, cppcheck does not do this well.
I am sure that visual studio also has such a warning.. I just don't know how you configure it.
I have searched a bit, but it seems that Visual Studio does not have such a warning. It can warn when
override
is specified but now allowed. But not if there is anoverride
missing.If someone finds information how to warn about missing
override
in Visual Studio i would be interested also.