Menu

duplInheritedMember false postitive with templates

2024-05-06
2024-05-07
  • Steve Albright

    Steve Albright - 2024-05-06

    Ignore that the code doesn't fully compile because of not actually being used (so it can't find the template type).

    The template seems to be confusing they check

    warning: duplInheritedMember - The class 'DupExampleImplementation' defines member function with name 'GetValue' also defined in its parent class 'DupExampleInterface'

    class DupExampleInterface
    {
    public:
       virtual ~DupExampleInterface() = default;
    
       virtual const QVariant& GetValue(int key) const = 0;
    };
    
    class DupExampleImplementation: public DupExampleInterface
    {
    public:
       ~DupExampleImplementation() override = default;
    
       template<class T>
       T GetValue(int key) const
       {
          const QVariant& v = GetValue(key);
          return v.value<T>();
       }
    };
    
     
  • CHR

    CHR - 2024-05-07

    So the idea is that the template parameters prevent any confusion between the two functions? Otherwise this looks like a true positive to me.

     
    • Steve Albright

      Steve Albright - 2024-05-07

      If you put override on the duplicate function, you get a compile error.

      The base is pure virtual and therefore has to be implemented and since there is no compile error it apparently is.

      So, I don't see a way to make this work without maybe adding specializations (which I don't want to do and seems odd if to fix this issue cppcheck would require it on compiling code).

       

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.