Menu

Override Rule in CppCheck

2019-03-12
2019-03-13
  • Sourabh Joshi

    Sourabh Joshi - 2019-03-12

    Consider the following Code snippet:
    #include <iostream>
    using namespace std;
    class MyClass : public std::basic_streambuf<char>
    {
    public :
    int_type overflow(int_type c = traits_type::eof());
    };</char></iostream>

    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()

     
  • Sourabh Joshi

    Sourabh Joshi - 2019-03-12

    There is unwanted characters in the above code
    Here is the updated code :

    include <iostream></iostream>

    using namespace std;
    class MyClass : public std::basic_streambuf<char>
    {
    public :
    int_type overflow(int_type c = traits_type::eof());
    };</char>

     

    Last edit: Sourabh Joshi 2019-03-12
  • versat

    versat - 2019-03-13

    You can insert / write code inside blocks sourrounded by ~~~ (each on its own line) to avoid that the code is changed / characters are inserted.
    Example:

    ~~~
    // write your code here
    ~~~

    Currently we do not have information in the Cppcheck library configuration whether a function is virtual. Not sure if that would really help or if it is some other bug.
    A ticket requesting to make it possible that functions can be marked virtual in the library configuration already exists:
    https://trac.cppcheck.net/ticket/8468

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.