Menu ▾ ▴

FP: duplInheritedMember and missingOverride when using namespace

2026-10-02
2026-10-05
  • Dan Workman

    Dan Workman - 2026-10-02

    We've had this issue for many releases so can't provide a version that it started

    Running
    cppcheck --std=c++20 --enable=style,warning --template=gcc repro.cpp
    on

    namespace Legacy
    {
    struct Base
    {
      int Count() const;
      virtual void Print() const;
      virtual ~Base() = default;
    };
    
    struct Position : Base
    {
    };
    }
    
    using namespace Legacy;
    
    namespace Modern
    {
    struct Position
    {
      int Count() const;
      void Print() const;
    };
    }
    

    gives

    repro.cpp:21:7: warning: The struct 'Position' defines member function with name 'Count' also defined in its parent struct 'Base'. [duplInheritedMember]
        int Count() const;
                ^
    repro.cpp:5:7: note: Parent function 'Base::Count'
        int Count() const;
                ^
    repro.cpp:21:7: note: Derived function 'Position::Count'
        int Count() const;
                ^
    repro.cpp:22:8: warning: The function 'Print' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]
        void Print() const;
                 ^
    repro.cpp:6:16: note: Virtual function in base class
        virtual void Print() const;
                                 ^
    repro.cpp:22:8: note: Function in derived class
        void Print() const;
                 ^
    

    We hit this regularly as we are slowly replacing a legacy implementation with a modern one and the two implementations differ only by namespace

     

    Last edit: Dan Workman 2026-10-02
  • CHR

    CHR - 2026-10-05

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

     

Log in to post a comment.