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

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 27 18:22:28 PDT 2017


alexfh added a comment.

In https://reviews.llvm.org/D35941#823020, @rnk wrote:

> I'm not really sure this is a bug. The point of -Wshadow is to warn on valid but possibly confusing code. Shadowing a variable is perfectly legal, but people think it's confusing, so we implemented this warning. Are we concerned that people might get confused between the different local variables here?


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, so the inner variable with the same name is not confusing (at least, much less confusing than if it would prevent access to the variable of an outer scope). This is close to shadowing of uncaptured locals in lambdas, but it seems to have even less potential for being misleading. We had a few of requests internally to mute `-Wshadow` for this case. Another data point is that GCC doesn't warn in this case.

But if I'm overseeing reasons to issue a warning in this case, we could add an analogue of `-Wshadow-uncaptured-local` for this case. WDYT?


https://reviews.llvm.org/D35941





More information about the cfe-commits mailing list