What are the name-lookup rules in a generic lambdas, if in the surrounding scope names from a different namespace are imported?
namespace ns
{
template <class F>
void bar2(F f) { f(0); }
template <class F>
void bar1(F f)
{
bar2(f); // (1)
}
}
void foo()
{
using namespace ns;
bar1([&](auto i) { // (2)
// using namespace ns; // (3)
bar1([&](auto j) {}); // (4)
});
}
int main()
{
foo();
}
The situation above gives different results in gcc
and intel icc
. While in gcc
it compiles without errors and warnings, in icc
I get the error message
error: identifier "bar1" is undefined
in line (4). See also https://godbolt.org/g/PYzWtw The situation changes if (1) is removed, or if in (3) the names from namespace ns
are imported again, or if in (2) and (4) auto
is replaced by int
. Thus, small changes, that seem irrelevant, make the code compile in icc
. In all cases, it compiles fine with gcc
.
Is this a bug in intels compiler?
My compiler setup: gcc 6.3.0, intel icc 18.0.1. Also with clang 4 it compiles fine.
Since it works with non-generic lambdas, I assume, the problem is related to the instantiation point of the lambda operator()
. But I don't get which compiler performs correctly.