Menu

false positive in v2.5 on reference variables

2021-10-05
2021-10-05
  • david ingamells

    david ingamells - 2021-10-05

    Hi,
    in version 2.5, on the following class method

            void Scale(double scale)
            {
                int num_points = int(m_polygon.m_points.size());
                for (int i = 0; i < num_points; ++i)
                {
                    niPoint2d & p = m_polygon.m_points[i];
                    p *= scale;
                }
            }
    

    I am getting the following error reported

    unreadVariable - Variable 'p' is assigned a value that is never used.
    

    Since p is a reference, the expression p *= scale is using p to refer to the value that will be scaled and p is not changed itself.

     
  • CHR

    CHR - 2021-10-05

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10531

     

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.