Menu

duplInheritedMember false positive

2024-01-20
2024-04-30
  • Igor Krivenko

    Igor Krivenko - 2024-01-20

    Hello,

    I would like to report what appears to be a duplInheritedMember false positive related to the final virtual function specifier.

    #include <memory>
    
    namespace ns {
    
    template<typename T>
    struct Base {
      virtual std::unique_ptr<Base> clone() const = 0;
    };
    
    struct Derived : public Base<int> {
      std::unique_ptr<Base<int>> clone() const final {
        return std::make_unique<Derived>(*this);
      }
    };
    
    }
    
    $ cppcheck --enable=warning --std=c++17 --verbose issue.hpp
    issue.hpp:11:30: warning: The struct 'Derived' defines member function with name 'clone' also defined in its parent struct 'Base < int >'. [duplInheritedMember]
      std::unique_ptr<Base<int>> clone() const final {
                                 ^
    issue.hpp:7:33: note: Parent function 'Base < int >::clone'
      virtual std::unique_ptr<Base> clone() const = 0;
                                    ^
    issue.hpp:11:30: note: Derived function 'Derived::clone'
      std::unique_ptr<Base<int>> clone() const final {
    

    Weirdly enough, the warning goes away if I remove the namespace from the example. Making the base class non-templated or changing final to override makes it disappear as well.

    Version info:
    cppcheck built from sources (d0a02bb)

     
  • CHR

    CHR - 2024-01-21

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12374

     
  • Steve Albright

    Steve Albright - 2024-04-30

    I have encountered the same issue.

     

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.