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

    <tr>
        <th>Summary</th>
        <td>
            crash-on-invalid on auto returning template in class, called before its definition
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            c++,
            crash-on-invalid
      </td>
    </tr>

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

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

<pre>
    ```
struct t1 {};
struct t2 {
  static void f1() { t1 ref_pos1 = f2<0>(); }
 template <int>
  static auto f2() {
    return t1();
 }
};
void f3() { t2::f1(); }
```
https://godbolt.org/z/ojo7sK7z5

GCC rejects this, and clang rejects it if `f2` isn't a template
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxskt9uozoQxp9muBklMmPA5YKLJjmci32IlQGTuOvYkT1ktX36lUmattFKFsh8Mz---aNTskdvTAf1DupDoRc-hdhNvwen7S9riiFMfzpoxP2IA4jXxHEZGblEUDtQB5C77wKtwvoJMbFmO-I12AnnEugFqM16zo9m_nkJqUSQB5wJ5F6A_O8WA3KHGX7DsDlfnGaDIPfWc476ztcLh4x48D90xGh4iR65fIDv2gP_tYibUfnVKIF8Bfk6l_9w9tSbE_Ml5XDqgfpjmIbgeBviEah_B-rDW1Dph3qv79nr8__9HqN5MyMn5JNNQHvUfsLRaX98KJbRzgiNmAkagTZ5IMWoH70ppk5OrWx1YbpSlUoJKpu2OHWt1KaqRzKmaquymeZxroZWDS_jaFSp5sJ2JKgSjWjKllpqt3VdCjVIobRSQ61eoBLmrK3bOnc953IKm9JiurZqmqZwejAurTtEtJoGIqB9vgHt1vNxjzqdNsFvrL9qZ6cs1Icidhm8GZZjgko4mzh9_ootO9M9Z2Lwt6Hfxmv98XNJrM-9S2sjR-2cmXAwc4gGLSeczGy9ZRt8sUTXPY3M8mkZtmM4A_XZwv21ucSQ5wDUr6UnoP5W_bWjvwEAAP__LV31Rw">