void f ( short ); // Example 1 template <typename T> void f ( T ); // Example 2 void b ( short s ) { f ( s ); // Noncompliant - Calls Example 1 f ( s + 1 ); // Noncompliant - Calls Example 2 }
If a function and a specialization of a function template are deemed equivalent after overload resolution, the non-specialized function will be chosen over the function specialization, which may be inconsistent with developer expectations.
void f ( short ); // Example 1 template <typename T> void f ( T ); // Example 2 void b ( short s ) { f ( s ); // Noncompliant - Calls Example 1 f ( s + 1 ); // Noncompliant - Calls Example 2 }
void f ( short ); // Example 1 template <typename T> void f ( T ); // Example 2 void b ( short s ) { f<>( s ); // Compliant - Explicitly calls Example 2 f<>( s + 1 ); // Compliant - Explicitly calls Example 2 }
This rule does not apply to copy constructors or copy assignment operators.
MISRA C++:2008, 14-8-2