https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68938
Bug ID: 68938
Summary: [C++11] use of lambda before deduction of auto does
not fail in templated function
Product: gcc
Version: 5.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sebastien.piat at epita dot fr
Target Milestone: ---
When testing the following code with g++ the compilation fails with error
"use of ‘print’ before deduction of ‘auto’"
===============================
#include <functional>
void bar()
{
auto print = std::function<void(int)>([&print](int n){ print(n); });
print(1);
}
int main()
{
bar();
return 0;
}
===============================
While the following code where the function is templated does compile.
===============================
#include <functional>
template <typename T>
void bar()
{
auto print = std::function<void(int)>([&print](int n){ print(n); });
print(1);
}
int main()
{
bar<int>();
return 0;
}
===============================
Compilation with clang++ fails in both cases with error:
"variable 'print' declared with 'auto' type cannot appear in its own
initializer"
It is my understanding that it should not work.
I have tested these with g++ version: Debian 5.2.1-21 and Debian 4.9.2-10.