ADL, normal lookup and dependent function call not working oO

Here is the simple code presented that should have worked according to the C ++ standard I believe :

template<typename T> 
void foo(T x) 
{ 
    bar(x); 
    void bar(int);
} 

void bar(int)  { } 

int main() 
{ 
    foo(0); 
} 

      

The error comes from GCC 4.7 as:

'was not declared in this scope, and no declarations were found depending on the search argument at the point of instantiation

But the C ++ standard says it. ยง 14.6.4.2:

For a function call that depends on a template parameter, candidate functions are found using normal search rules (3.4.1, 3.4.2, 3.4.3), except that:

... For the search part using unqualified name lookup (3.4.1) or qualified name lookup (3.4.3), function declarations are found from the context of the template definition.

I may have a misconception about what is written, can someone please correct me here?

+3


source to share


1 answer


You just need to move the ad "bar" to the top. Because at the moment when the template is defined (not created), it is not declared before the call to "bar".



0


source







All Articles