Menu

False positive noConstructor on inner struct of template class specialization

2023-07-20
2023-07-20
  • Sylvain Joubert

    Sylvain Joubert - 2023-07-20

    I'm not sure what happens. Maybe a is wrongly assigned to the inner class. Note that if Inner has a default implementation and is not forward declared, the warning still appears, as long as it is specialized afterward.

     cppcheck --version
    Cppcheck 2.11
    
    ❯ cat test.cpp 
    template <typename T>
    class Test
    {
    public:
      Test();
      int& get() { return a; }
    
    private:
      struct Inner; // or struct Inner {};
    
      int& a;
    };
    
    template <>
    struct Test<int>::Inner
    {
    }; cppcheck --enable=style --std=c++20 test.cpp 
    Checking test.cpp ...
    test.cpp:2:1: style: The class 'Inner' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]
    class Test
    ^
    
     
  • CHR

    CHR - 2023-07-20
     

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.