Menu

False positive "constVariable" with reference to std::array

2023-02-07
2023-02-07
  • Dan Workman

    Dan Workman - 2023-02-07

    Found in 2.10

    #include <iostream>
    #include <array>
    
    std::array<int, 1> foo;
    std::array<int, 1> bar;
    
    int main()
    {
      foo[0] = 0;
      bar[0] = 0;
    
      const auto& ints = foo;
      std::cout << (ints == bar);
    
      return 0;
    }
    

    Output:

    $ cppcheck --std=c++17 --enable=all --platform=win64 cppcheck_false_positives.cpp
    Checking cppcheck_false_positives.cpp ...
    cppcheck_false_positives.cpp:15:15: style: Variable 'ints' can be declared as pointer to const [constVariable]
      const auto& ints = foo;
                  ^
    
     

    Last edit: Dan Workman 2023-02-07
  • CHR

    CHR - 2023-02-07

    Thanks for reporting, fixed by https://github.com/danmar/cppcheck/pull/4777

     
    👍
    1

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.