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

S1751, S1763: deduplicate, prefer specific S1751 over generic S1763

    Details

      Description

      The following range for loop triggers two rules:

      void f() {
        int a[3] = {1, 2, 3};
        for (int x : a) {
          (void)x;
          return;
        }
      }
      

      Both S1763 and S1751 will highlight the for keyword and report:

      loop will run at most once (loop increment never executed)

      Change this loop body so that it can be executed more than once.

      RSPEC-1751 is more specific and better describes the case at hand, while RSPEC-1763 has a non-actionable and potentially confusing message (the loop increment in a range loop is not evident).

      Considering the above, rule S1763 should keep silent for the cases handled by S1751.

      Related duplicate reports:

        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: