37 lines
837 B
Plaintext
37 lines
837 B
Plaintext
== Why is this an issue?
|
|
|
|
Argument-dependent lookup (ADL) adds additional associated namespaces to the set of scopes searched when lookup is performed for the names of called functions. A generic function found in one of these additional namespaces would be added to the overload set and chosen by overload resolution, which is inconsistent with developer expectation.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
template <typename T>
|
|
class B
|
|
{
|
|
public:
|
|
B operator+ ( long & rhs );
|
|
void f ( )
|
|
{
|
|
*this + 10; // calls NS::operator+ and not B<NS::A>::operator+ when B is instantiated with NS::A
|
|
}
|
|
};
|
|
|
|
namespace NS
|
|
{
|
|
class A {
|
|
public:
|
|
};
|
|
template <typename T>
|
|
bool operator+ ( T, int32_t ); // Noncompliant, within associated namespace
|
|
}
|
|
template class B<NS::A>;
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA {cpp}:2008, 14-5-1
|
|
|