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

S1066: Fix false-positives by considering if constexpr, if statment with initializer, and macro if statment

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.7
    • Component/s: C++, Rules
    • Labels:
      None

      Description

      Macro:

      #define A(a) if (a>0)
      void macro(int a) {
        A(a) {
          if (a > 2) {
            // ..
          }
        }
      
        if (a > 2) {
          A(a) {
            // ..
          }
        }
      }
      

      C++17:

      struct S {
        int x;
        float y;
      };
      S f();
      
      void cpp17(int a) {
        if constexpr(true) {
          if (a) {
            // ...
          }
        }
      
        if (int b = a; b > 10) {
          if (bool c =  (2 * a) > 20; c) {
            // ...
          }
        }
      
        if (auto [x, y] = f(); x > 10) {
          if (bool c = (2 * a) > 20; c) {
            // ...
          }
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              abbas.sabra Abbas Sabra
              Reporter:
              massimo.paladin Massimo PALADIN
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: