[cxx-abi-dev] namespace-qualified unresolved-names

David Vandevoorde daveed at edg.com
Fri Apr 29 21:41:23 UTC 2011


On Apr 24, 2011, at 2:22 AM, John McCall wrote:

> Consider the following:
> 
>  namespace ns {
>    int foo(int);
>    short foo(short);
>  }
> 
>  template <typename T> auto forward_foo(T t) -> decltype(ns::foo(t)) {
>    return ns::foo(t);
>  }
> 
>  short test(short x) { return forward_foo(x); }
> 
> gcc-4.6 mangles forward_foo<short> as:
>  _Z11forward_fooIsEDTcl3foofp_EET_
> 
> This seems obviously wrong:  the qualifier has completely disappeared,
> and this now looks like an unqualified call.  I believe the correct
> mangling falls under the fourth production for <unresolved-name>:
>  <unresolved-name> ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
> In that case, the mangling should be:
>  _Z11forward_fooIsEDTclsr2nsE3foofp_EET_
> 
> Right?


Yes.  (That's what we produce.)

>  I just want to verify that, because I have some follow-ups. :)
> 
> 1. When mangling a namespace qualifier for an unresolved-name,
> should we mangle the full namespace path or just what was written?
>  namespace outer {
>    namespace ns { ... }
>    template <typename T> auto forward_foo(T t) -> decltype(ns::foo(t));
>    // sr2nsE3foo or sr5outer2nsE3foo or gssr5outer2nsE3foo ?
>  }
> 
> The 'gs' does not seem to be useful in the case of a non-member
> unresolved-name with a qualifier.



Generally speaking, I think the encoding should reflect the source form.  So here that argues for sr2nsE3foo.

(I agree with James' arguments here.)


> 
> 2. Should we look through template aliases?
>  namespace alias = ns;
>  template <typename T> auto forward_foo(T t) -> decltype(alias::foo(t));
>  // sr2nsE3foo or sr5aliasE3foo ?


Good question.  Our current implementation reflects the source form: sr5aliasE3foo.  However we do "look through" typedefs; so perhaps looking through namespace aliases would make more sense.


> 
> 2a. If we look through template aliases, what happens to prefix
> nested name specifiers?
>  namespace nsx { namespace alias = ns; }
>  template <typename T> auto forward_foo(T t) -> decltype(nsx::alias::foo(t));
>  // sr2nsE3foo ?



We produce sr3nsx5aliasE3foo.


> 
> 2b. Specifically, what about global prefixes?
>  template <typename T> auto forward_foo(T t) -> decltype(::alias::foo(t));
>  // sr2nsE3foo or gssr2nsE3foo ?


We produce gssr5aliasE3foo.

	Daveed




More information about the cxx-abi-dev mailing list