Menu

Found suspicious operator ',' [constStatement] warning for 2d std array

haroim
2020-06-12
2020-06-12
  • haroim

    haroim - 2020-06-12

    I have a piece of code which cppcheck warns me about, but I can't find out why.

    If I declare "std::array<std::array<double,3>,3> array;" in a file, it warns: "warning: Found suspicious operator ',' [constStatement]", when I use the --enable=all option.</std::array<double,3>

    I have reproduced this with just a cpp file with one function containing just this statement and one where I added the same statement with an initializer:

    void Test()
     {
       std::array<std::array<double,3>,3> array;
       std::array<std::array<int, 3>, 3> arr = {{{5, 8, 2}, {8, 3, 1}, {5, 3, 9}}};
     }
     ```
    
     The result is:
    
     ```
     Checking test.cpp ...
    test.cpp:3:34: warning: Found suspicious operator ',' [constStatement]
      std::array<std::array<double,3>,3> array;
                                     ^
    test.cpp:4:32: warning: Found suspicious operator ',' [constStatement]
      std::array<std::array<int, 3>, 3> arr = {{{5, 8, 2}, {8, 3, 1}, {5, 3, 9}}};
                                   ^
    test.cpp:1:0: style: The function 'Test' is never used. [unusedFunction]
    

    I am wondering whether this is a bug or if there is a real concern here. Thanks!

     

    Last edit: haroim 2020-06-12
  • Daniel Marjamäki

    Thanks! No real concern, Cppcheck is wrong. I created this ticket:
    https://trac.cppcheck.net/ticket/9766

     
  • haroim

    haroim - 2020-06-12

    Thanks for the quick reply!

     

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.