Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-2795

S1763: Improve the location for the unreachable code report, involving "operator[]"

    Details

      Description

      When an operator[] is the first thing an unreachable code invokes, the reporting location might confuse the user. Here:

      struct vect {
        int operator [](int i) const;
      };
      
      void f(const vect& vector) {
        return;
        const int x = vector[0];
        //   reported here: ^^^
      }
      

      The issue points to [0], which might not be immediately seen as executable.
      To make the message more understandable, the rule should choose another location (e.g. the assignment), or mention the operator directly, to make it clear that that is not just a compile-time pointer shift.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                arseniy.zaostrovnykh Arseniy Zaostrovnykh
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: