I've came accross a strange namespace scoping behavior (using g++ 4.8.2). To explain the problem I've extracted a minimal code that reproduces this strange behavior:
namespace Weird {
template <typename T>
struct Rec
{
T val;
Rec( T const& _val ) : val( _val ) {}
};
template <typename T>
Rec<T>
foo( Rec<T> const& r )
{
return Rec<T>( r.val * 2 );
}
};
Weird::Rec<double>
bar( Weird::Rec<double> const& _input )
{
return foo( _input );
}
In this code I would have expect G++ to complain about "foo" not being defined in the scope of "bar", which is not the case; the code just compiles fine.
So I'm a bit confused. Is g++ wrong (namespace leak)? Or if not, according to which mechanism does "foo" becomes visible in "bar" ?