Clarification on C++ name lookup
<p>I have a question about a situation I just came upon at work.</p>

<p>setup:
in stringStuff.h</p>

<pre><code>namespace n1
{
namespace n2
{
    typedef std::string myString;
}
}

namespace n1
{
namespace n2
{
    void LTrim(myString&amp; io_string);
    void RTrim(myString&amp; io_string);

    inline void Trim(myString&amp; io_string)
    {
        LTrim(io_string);
        RTrim(io_string);
    }
}
}
</code></pre>

<p>in impl.cpp</p>

<pre><code>#include "stringStuff.h" // This actually gets included via other include files
#include "globalInclude.h" // contains 'using namespace n1::n2;'. Yes, I know this isn't best practice

inline static myString Trim(const myString&amp; in_string)
{
    // impl
}

static void impl(const myString&amp; in_string, myString&amp; out_string)
{
    size_t N = 10; // just some computed value.
    out_string = Trim(in_string.substr(1, N)); // This is the line with the error
}
</code></pre>

<p>now, I admit I don't understand C++ name resolution rules quite as well as I should, but when I look at this, it seems like the call to Trim <em>should</em> be ambiguous. </p>

<p>The surprising thing is that it compiles just fine on Linux using GCC, calling the function defined in impl.cpp. When I compile on HP-UX using its native compiler, it seems to resolve the call as the one defined in stringStuff.h, and complains about converting a temporary to a non-const ref (which is surprisingly a warning, not an error), and about trying to assign void to a myString.</p>

<p>What should be happening according to the C++ standard, and which compiler (if either) is getting it right?</p>

<p>BTW, I 'fixed' it in my case by prefixing the call to trim with ::, although that isn't really ideal.</p>
