Menu

typedef with non-primitive type

David Lin
2019-03-27
2019-04-01
  • David Lin

    David Lin - 2019-03-27

    Hi,
    I found that cppcheck sometimes not working well with non-primitive typedef.

    Version: 1.87

    cppcheck --enable=style

    With following code snippet, cppcheck can find and emit warning

    (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier.
    
    class A {
        public:
            typedef int Type;
            virtual void foo(Type);
    };
    class B : public A {
        void foo(Type);
    };
    

    Howerever,
    If Type is defined as std::vector

    class A {
        public:
            typedef std::vector<int> Type;
            virtual void foo(Type) ;
    };
    class B : public A {
        void foo(Type);
    };
    

    cppcheck will no longer emit any warnings.

    The following are 2 cases that cppcheck will also emit warning.
    Case 1:

    typedef std::vector<int> Type;
    class A {
        public:
            virtual void foo(Type) ;
    };
    class B : public A {
        void foo(Type);
    };
    

    Case2:

    class A {
        public:
            typedef std::vector<int> Type;
            virtual void foo(Type) ;
    };
    class B : public A {
        void foo(std::vector<int>);
    };
    

    Looks like that cppcheck is confused with the typedef if both conditions are met:
    1. typedef with non-primitive data type
    2. typedef in base class scope

    Is it a possible bug?

    Thanks and regards,
    David

     

    Last edit: David Lin 2019-03-28
  • David Lin

    David Lin - 2019-03-31

    Update:
    Lookes like the Type is not correctly deducted from base class's typedef.

    But what make me curious is that cppcheck behaves differently by putting typedef out of base class scope.

    Shall we have a ticket for this if it is confirmed bug?

    I would appreciate if this issue can be fixed.

    Thanks,
    David

     
  • versat

    versat - 2019-04-01

    IMHO it is a false negative, so i created a ticket: https://trac.cppcheck.net/ticket/9086

     
    👍
    1

    Last edit: versat 2019-04-01
    • David Lin

      David Lin - 2019-04-01

      Thank you for confirming this issue.

      Thanks,
      David

       

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.