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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 05:11:00 PDT 2017


aaron.ballman added inline comments.


================
Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}
----------------
baloghadamsoftware wrote:
> xazax.hun wrote:
> > baloghadamsoftware wrote:
> > > aaron.ballman wrote:
> > > > This fix-it worries me because it changes the semantics of the code. The function `f()` is no longer called, and so this isn't a valid source transformation.
> > > Maybe the correct fix would be here f(1, 2, 3, 4); C::x;
> > Maybe for now we should just skip this cases. Expr::HasSideEffects might be a  good candidate to filter these cases. 
> I think including the expression with side effect before the member access (as I suggested) is not more complicated than skipping these cases.
Please ensure you handle the more complex cases then, such as:
```
struct S {
  static int X;
};

void g(int &);
S h();

void f(S s) {
  g(h().X);
  if ([s]() { return s; }().X == 15)
    ;
}
```


Repository:
  rL LLVM

https://reviews.llvm.org/D35937





More information about the cfe-commits mailing list