[Bug c++/78850] New: Parameter of returned generic lambda allegedly shadows parameter of free function

daiw at gmx dot net gcc-bugzilla@gcc.gnu.org
Sun Dec 18 14:16:00 GMT 2016


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

            Bug ID: 78850
           Summary: Parameter of returned generic lambda allegedly shadows
                    parameter of free function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daiw at gmx dot net
  Target Milestone: ---

Compiling the following code

    template <typename X, typename F>
    auto apply(X x, F f)
    {
        return f(x);
    }

    template <typename Y>
    auto add_value(Y y)
    {
        return [y](auto x)
        {
            return x + y;
        };
    }

    int main()
    {
        apply(1, add_value(2));
    }

with g++ (e.g. v. 5.4, but also newer ones) gives false shadow warnings:
https://godbolt.org/g/MMJ51o

    $ g++ -Wshadow -Werror -std=c++14 shadow_test.cpp 
    shadow_test.cpp: In instantiation of ‘add_value(Y)::<lambda(auto:1)> [with
auto:1 = int; Y = int]’:
    shadow_test.cpp:4:13:   required from ‘auto apply(X, F) [with X = int; F =
add_value(Y) [with Y = int]::<lambda(auto:1)>]’
    shadow_test.cpp:18:26:   required from here
    shadow_test.cpp:10:22: error: declaration of ‘int x’ shadows a parameter
[-Werror=shadow]
         return [y](auto x)
                          ^
    shadow_test.cpp:2:14: note: shadowed declaration is here
     auto apply(X x, F f)
                  ^
    cc1plus: all warnings being treated as errors

Corresponding SO post:
http://stackoverflow.com/questions/41208811/parameter-of-returned-generic-lambda-allegedly-shadows-parameter-of-free-functio


More information about the Gcc-bugs mailing list