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

    <tr>
        <th>Summary</th>
        <td>
            Template arg type invalid if class in namespace
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          cnx-tcsikos
      </td>
    </tr>
</table>

<pre>
    Hi!

I'm trying to parse this simplified code ( only for AST, so "-E -dM" )
File1.hpp
```cpp
  namespace N1 {
    template <typename... Args>
    class TemplatedClass{};
  }
```

main.hpp
```cpp
#include ""File1.hpp""

class MyClass
{
public:
  N1::TemplatedClass<int>& get();
};
```

When the AST's cursor gets to `get()` function's return type, it correctly states that its a `ClassTemplateSpecializationDecl` and has 1 template arg. However when I try to `getTemplateArgs().get(0)` it is invalid for AsType.

I had encountered this issue when I upgraded from Clang10 to Clang12. I verified that the issue still present in latest Clang (15.0.2)

Some extra leads on debugging this:
- The Invalid type only occurs when `TemplatedClass` is inside a namespace and is included from a different file . If neither is true the issue cease to exist.
- I'm using libclang through ClangSharp, if that matters
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VMGOmzAQ_Rq4jILABNIcOKS7XXUP7WUj9eyYAdw6NrLNbtOv79gOm7SqKhGC8TDz3ps3Ppn-0n2WGauy8jErD-n-nLHdGby9SD2CNzBz6xD8JB04eZ6VHCT2IEyPkLEPYLS6wGAsHF6OGXsAZ-g123yCTf-FHmixT3mfpMKqmOb5Wqwt0yXWNwCan9HNXCB8rSDbfVzfA3ikytxTyfrBX2YMkUVRwMGOLqs_3QKF4s7B8RreP4RlyLR7zOr3fGH1J4h7Ac5c6v_hzFgttVBLFIDRdWMWl_e5Epwvl4Qjbay85uWkpMjqwwrraxUW9eEv9PWD1D6QZC2M6En0oOnK5p7ZP-l8m1BT-zA1aOdALNZRvyiVC_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