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

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 11 06:05:44 PDT 2017


alexfh added a comment.

In https://reviews.llvm.org/D35941#838633, @rsmith wrote:

> 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};
>   }
>


Good to know!

> 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.

Sounds reasonable.


Repository:
  rL LLVM

https://reviews.llvm.org/D35941





More information about the cfe-commits mailing list