[PATCH] D35941: Fix -Wshadow false positives with function-local classes.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 10 16:52:22 PDT 2017


rsmith added a comment.

In https://reviews.llvm.org/D35941#823524, @alexfh wrote:

> IIUC, most cases where -Wshadow warnings are issued is when a declaration from an enclosing scope would be accessible if there was no declaration that shadows it. In this case the the local variable of a function would not be accessible inside the local class anyway


That's not strictly true; the variable can be accessed in unevaluated operands, and in code doing so, a `-Wshadow` warning might (theoretically) be useful:

  void f(SomeComplexType val) {
    struct A {
      decltype(val) &ref;
      void g(int val) {
        decltype(val) *p = &ref;
      }
    } a = {val};
  }

That said, suppressing the warning seems like a good thing in the common case. We've discussed the idea of deferring some `-Wshadow` warnings until we see a use; if someone cares about this case, we could consider warning only if the shadowed variable is actually used in an unevaluated operand.


Repository:
  rL LLVM

https://reviews.llvm.org/D35941





More information about the cfe-commits mailing list