1

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.

spraetor
  • 441
  • 4
  • 13
  • I think I've just come across the same problem. Have you any update on this? – ThreeStarProgrammer57 Dec 14 '18 at 17:28
  • 1
    Also in icc 19 the error is not resolved. Since it compiles fine in all the other major compilers gcc, clang, msvc I assume this is just a problem if intel. It can be resolved by `using namespace ns` also inside the first lambda, so that the name `bar1` gets imported again. – spraetor Dec 15 '18 at 18:33

0 Answers0