3

Is the code below valid C++98 or does it require a newer version of the C++ standard?

namespace basic
{
  void f(int) {}
}

namespace lib
{
  template<class T1, class T2>
  void g(T1 x1, T2 x2)
  {
    using basic::f; // pull in function f for basic types without ADL
    f(x1);
    f(x2); // error: no suitable conversion function from "user::c" to "int" exists
  }
}

namespace user
{
  class c {};

  void f(c) {}
}

int main()
{
  lib::g(1, user::c());
}

Apparently, my compiler (based on EDG front end, I guess) does not consider user::f after the using declaration of basic::f. Is this correct behavior according to C++98?

1 Answers1

2

I think that it's not correct behaviour of your compiler. Your template should be only actually resolved / instantiated after the point of declaration of use. So at that point it should resolve the names for that instantiation, and those include the ADL-pulled in lookup, so that should have worked.

I think MSVC still has a pending thing to do this two-phase lookup though, and your compiler (EDG frontend? What's the name of the compiler) may also do that. I know for a fact that MSVC2015 does not do a proper two-phase lookup, but I don't know for sure if that applies to this example, and your implication is that you're not using that compiler.

dascandy
  • 7,184
  • 1
  • 29
  • 50
  • The name of the compiler is Wind River Diab Compiler version 5.5. – Jesper Schmidt Oct 08 '15 at 12:55
  • Can't blame them for getting wrong what Visual Studio 2015 still gets wrong too... although it's a shame that companies as big as this are getting away with not even supporting full C++98 - and that's not referring to the parts deprecated by now. – dascandy Oct 08 '15 at 19:15