[PATCH] D18271: Avoid -Wshadow warnings about constructor parameters named after fields

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 11:08:41 PDT 2016


rnk added a comment.

I'm not sure your example is in scope for -Wshadow, though. Any function call that takes a non-const reference to the parameter could modify it. I guess I'm thinking something like:

  void trim_in_place(std::string &s);
  struct A {
    std::string s;
    A(std::string s) : s(s) { trim_in_place(s); }
  };

I think if we try to match that we'll have too many false positives.

I think your example would be better caught by something like -Wconsumed that looks for uses of objects that have been moved-from. That warning won't be confused by shadowing and will give a better diagnostic anyway.


http://reviews.llvm.org/D18271





More information about the cfe-commits mailing list