[Bug c++/79328] New: Wshadow and lambda captures

nathan at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 1 16:53:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79328

            Bug ID: 79328
           Summary: Wshadow and lambda captures
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nathan at gcc dot gnu.org
  Target Milestone: ---

Created attachment 40647
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40647&action=edit
example

-Wshadow warnings have a confusing interaction with lambda captures.
1) The names of init lambda captures are not checked.
2) local names are checked regardless of whether there is a default capture to
make an outer object accessible

The original report also mentioned the following case:
T x;
[=, x = std::move(x)] {};
if T is a non-copyable type, the default = capture couldn't capture it.

IMHO such nuance shouldn't affect whether or not this gives a warning (so it
should warn).

I think it clear that #1 should be checked, but I can see arguments for and
against #2.  I think of name hiding as (almost) a syntactic check, and whether
an object can be captured is more of a semantic check.


More information about the Gcc-bugs mailing list