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

    <tr>
        <th>Summary</th>
        <td>
            using declaration treated as separate type in out-of-line template method definition
        </td>
    </tr>

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

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

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

<pre>
    Here we have a `Leaf<Branch<Root<SpeciesT>>>` type. The `Root<SpeciesT>` type defines a type `using Species = SpeciesT`, so all subclasses of the same `Root<SpeciesT>` have the same `Species` type variable.

The `Leaf` class has a using declaration to bring the `Species` type into scope. The return type of `branch_two()` uses this `Species` type. The Clang bug is avoided if either:
a) The using declaration is replaced with a type alias of the same name: `using Species = typename Branch::Species;`
b) The full path of the type is used instead of the type from the using declaration: Useing `typename Branch::Species` explicitly.

However, since this code uses the type pulled in by the using declaration, it fails to compile in Clang. It works in GCC and MSVC.

The failure is that the method definition uses the fill path to the type, `Branch::Species` and Clang reports that this is a different type than the `Species` in the method's declaration, which was a using declaration of the `Branch::Species` type.

Godbolt: https://godbolt.org/z/GEMeGs65d

```cpp

template <class SpeciesT>
class Root {
   public:
    using Species = SpeciesT;
};

template <class SpeciesT>
class BranchTwo : public Root<SpeciesT> {};

template <class Branch>
class Leaf final : public Branch {
    using /* Species = */ typename Branch::Species;

    Leaf<BranchTwo</* typename Branch::*/ Species>> branch_two();
};

template <class Branch>
Leaf<BranchTwo<typename Branch::Species>> Leaf<Branch>::branch_two() {}
```

```
<source>:19:57: error: return type of out-of-line definition of 'Leaf::branch_two' differs from that in the declaration
Leaf<BranchTwo<typename Branch::Species>> Leaf<Branch>::branch_two() {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~               ^
<source>:15:53: note: previous declaration is here
    Leaf<BranchTwo</* typename Branch::*/ Species>> branch_two();
    ~~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