[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 01:26:22 PDT 2017


baloghadamsoftware added a comment.

I am not sure whether we should copy with such ugly things as overloaded member access operators with side effects, but they can also cause troubles using this fix:

  #include <iostream>
  
  using std::cout;
  using std::endl;
  
  struct C {
    static int N;
    int n = 0;
  };
  
  int C::N = 0;
  
  struct Cptr {
    C* c;
  
    explicit Cptr(C *cc): c(cc) {}
  
    C* operator->() {
      ++c->n;
      return c;
    }
  };
  
  int main() {
    Cptr cp(new C);
    cout<<"n: "<<cp->n<<endl;
    cp->N = 10;
    cout<<"n: "<<cp->n<<endl;
  }

Output:

  n: 1
  n: 3

After the fix, the output chanes to:

  n: 1
  n: 2


Repository:
  rL LLVM

https://reviews.llvm.org/D35937





More information about the cfe-commits mailing list