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

    <tr>
        <th>Summary</th>
        <td>
            CTAD: incorrect transformed require-clause for the alias deduction guide
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            c++20,
            clang:frontend
      </td>
    </tr>

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

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

<pre>
    Example:

```
struct Key1  {};

template <class Key>
struct Foo {
 Foo(Key);
};

template <class D>
constexpr bool C = sizeof(D);

template <class Key>
  requires (C<Key>)
Foo(Key) -> Foo<Key>;

template <class T>
struct HasTemplateParam {
 template <class Key>
  using Alias = Foo<Key>;
};

class Forward;
struct Test : HasTemplateParam<Forward> {
  using Foo1 = decltype(Alias{
    Key1(),
  });
};
```

clang rejects the above valid code with the following diagnostics:

```
<source>:9:20: error: invalid application of 'sizeof' to an incomplete type 'Forward'
 9 | constexpr bool C = sizeof(D);
      | ^~~~~~~~~
<source>:12:13: note: in instantiation of variable template specialization 'C<Forward>' requested here
   12 |   requires (C<Key>)
 |             ^
<source>:12:13: note: while substituting template arguments into constraint expression here
   12 |   requires (C<Key>)
 |             ^~~~~~
<source>:23:25: note: while checking constraint satisfaction for template '<deduction guide for Alias><Forward>' required here
   23 |   using Foo1 = decltype(Alias{
      | ^~~~~
<source>:23:25: note: in instantiation of function template specialization 'HasTemplateParam<Forward>::<deduction guide for Alias><Key1>' requested here
<source>:21:7: note: forward declaration of 'Forward'
 21 | class Forward;
```

It seems to be an issue in the transformed require-clause for the alias deduction guide. The require expression should be evaluated on  the type `Key1`, rather than the outer type `Forward`.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysls1yozgQx59GXFRxQcvm48DBwXbt1l72kBcQojHakSWvJJKZOeyzb0lghyTOx2wtRZGAWupf_9XdMndOHjViTTb3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