[Bug c++/78850] Parameter of returned generic lambda allegedly shadows parameter of free function
miklcct at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 31 17:31:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78850
Michael Tsang <miklcct at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |miklcct at gmail dot com
--- Comment #1 from Michael Tsang <miklcct at gmail dot com> ---
I think the following is related to this, where the parameter of a returned
lambda is mis-interpreted as shadowing a local variable:
[michael@samsung-rv510 ~]$ cat fix.cpp
#include <iostream>
using std::cin;
using std::cout;
struct Factorial {
template<class Function> unsigned long operator()(Function self, unsigned
long n) const {
return n ? n * self(self, n - 1) : 1;
}
};
template<class Function> auto y(Function f) {
return [f](auto n) {
return f(f, n);
};
}
int main() {
unsigned long n;
cin >> n;
cout << y(Factorial())(n) << '\n';
return 0;
}
[michael@samsung-rv510 ~]$ g++ -Wshadow -std=c++14 fix.cpp -o fix
fix.cpp: In instantiation of 'y(Function)::<lambda(auto:1)> [with auto:1 = long
unsigned int; Function = Factorial]':
fix.cpp:21:29: required from here
fix.cpp:13:22: warning: declaration of 'n' shadows a previous local [-Wshadow]
return [f](auto n) {
^
fix.cpp:19:19: note: shadowed declaration is here
unsigned long n;
^
More information about the Gcc-bugs
mailing list