title: Parameter of returned generic lambda allegedly shadows parameter of free function
body: <p>Compiling the following code</p>
  
  <pre><code>template &lt;typename X, typename F&gt;
  auto apply(X x, F f)
  {
      return f(x);
  }
  
  template &lt;typename Y&gt;
  auto add_value(Y y)
  {
      return [y](auto x)
      {
          return x + y;
      };
  }
  
  int main()
  {
      apply(1, add_value(2));
  }
  </code></pre>
  
  <p>with g++ (e.g. v. 5.4) gives <a href="https://godbolt.org/g/MMJ51o" rel="noreferrer">shadow warnings</a>.</p>
  
  <pre><code>$ g++ -Wshadow -Werror -std=c++14 shadow_test.cpp 
  shadow_test.cpp: In instantiation of ‘add_value(Y)::&lt;lambda(auto:1)&gt; [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]::&lt;lambda(auto:1)&gt;]’
  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
  </code></pre>
  
  <p>I do not understand why. Can anybody explain?</p>