Argument-dependent lookup (ADL) adds additional associated namespaces to the set of scopes searched when lookup is performed for the names of called functions. For function templates, ADL is performed at the point of instantiation of the function template, and so it is possible that a function declared after the template may be called.


To ensure that ADL does not take place when calling a function with a dependent argument, the postfix-expression denoting the called function can either be a qualified name or a parenthesized expression.


Operators with dependent types may also have this problem. In order to avoid ADL in these examples, operators should not be overloaded, or the calls should be changed to use explicit function call syntax and a qualified name or parenthesized expression used, as above.


== Noncompliant Code Example

----
void b ( int32_t );

template <typename T>
void f ( T const & t )
{
  b ( t ); // Non-compliant - Calls NS::b declared after f
  ::b ( t ); // Compliant - Calls ::b
  ( b ) ( t ); // Compliant - Calls ::b

  t == t; // Noncompliant - Calls NS::operator== declared after f
  ::operator ==( t, t ); // Compliant - Calls built-in operator==
  ( operator == <T> ) ( t, t ); // Compliant - Calls built-in operator==
}

namespace NS
{
  struct A
  {
    operator int32_t ( ) const;
  };
  void b ( A const & a );
  bool operator== ( A const &, A const & );
}

int main ( )
{
  NS::A a;
  f ( a );
}
----


== See

* MISRA {cpp}:2008, 14-6-2



ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
