<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/136624>136624</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Incorrect name qualification in AST / diagnostics for alias CTAD
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            mizvekov
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mizvekov
      </td>
    </tr>
</table>

<pre>
    Consider this example: https://compiler-explorer.com/z/bGqdsa3qc

```C++
template<typename U> struct A {
  U t;
};

template<typename V> A(V) -> A<V>;

namespace foo {
  template<class Y> using Alias = A<Y>;
}

foo::Alias t = 0;
```

Produces:
```
error: no viable conversion from 'int' to 'foo::A<int>' (aka 'A<int>')
```

Note that the `foo::` qualification is applied to Alias in the source code, which is in that namespace, but
on the AST (and consequently in the diagnostic) it gets applied to `A` , where it cannot be found.

The problem here is many fold:
1) We have an elaborated type including `foo::` over the deduced template specialization (DTST), which names `foo::Alias`.
2) However, when printing a DTST which has already been deduced, we choose to print it as the deduced type instead, probably for diagnostics reasons (although this is wrong for -ast-print, and we don't control this with a policy).
3) For alias CTAD, we don't build a guide which actually contains the alias template specialization `Alias<int>`, instead the guide contains `A<int>`.

I see  a couple of solutions:
* If we fix 3, then this would print as intended: `'foo::Alias<int>' (aka 'A<int>')`
* We could stop doing 2, then this would print as `'foo::Alias' (aka 'A<int>')`.
 The first type does not include much information, as 2) probably intended to avoid, but it is correctly qualified, and then the 'aka' gives the missing information.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVU2P2zYQ_TX0ZbALLWVL8cEHxRu3uRQFskmR44gcWWwoUktS3ji_vhhKdtZp-gEIsCXO13vzZogxmqMj2onNWyHlYL6d6Is_CSnF5nGFU-p92F2-rlqvz7u9d9FoCpB6E4G-4jBaEmUDfUpjFGUj5EHIg_LDaCyFO_o6Wh8o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