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

Report mutation for a static var mutated indirectly via a reference field in a class.

    XMLWordPrintable

    Details

      Description

      Enable these two tests:

      TEST(PotentialFavorMutationTest, NestedStructInFunctionPtrMutation) {
        const auto ast = buildASTFromCode("void f() {"
                                          "  static int x{0};"
                                          "  struct S { int* ptr = &x; void m() {*ptr=1;} } s;"
                                          "  s.m();"
                                          "}");
        const auto ResultDecl = match(withEnclosingCompound(declName("x")), ast->getASTContext());
        EXPECT_TRUE(isDeclMutated(ResultDecl, ast.get()));
      }
      
      TEST(PotentialFavorMutationTest, NestedStructInFunctionRefMutation) {
        const auto ast = buildASTFromCode("void f() {"
                                          "  static int x{0};"
                                          "  struct S { int& ref = x; void m() {ref=1;} } s;"
                                          "  s.m();"
                                          "}");
        const auto ResultDecl = match(withEnclosingCompound(declName("x")), ast->getASTContext());
        EXPECT_TRUE(isDeclMutated(ResultDecl, ast.get()));
      }
      
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated: