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

    <tr>
        <th>Summary</th>
        <td>
            Clang gives incorrect error about constraint depending upon itself
        </td>
    </tr>

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

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

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

<pre>
    Here is a simple program where we construct a `std::function` from a callable type with a templated constructor. The constructor is compatible with any input where it can create its own copy from the input forwarding reference.

```c++
#include <functional>
#include <type_traits>

struct Callable {
    Callable() = default;
 Callable(const Callable&) = default;
    Callable& operator=(const Callable&) = default;

    template <typename F>
    requires requires {
      // We don't want this constructor to interfere with the copy
      // constructor.
      requires(!std::is_same_v<Callable, std::decay_t<F>>);

      // It must be possible to make our own copy of the input from
      // the input reference.
      requires std::is_constructible_v<std::decay_t<F>, F>;
    }
    Callable(F&& f);

    int operator()();
};

void foo() { std::function<int()> f = Callable{}; }
```

GCC [accepts](https://godbolt.org/z/PchvYqG68) this program as valid with `-std=c++20`, but clang [rejects it](https://godbolt.org/z/YzxE68Pfn) at trunk using `-std=c++20 -stdlib=libc++`, with the following error:

```
<source>:10:14: error: satisfaction of constraint 'requires { requires (!std::is_same_v<Callable, std::decay_t<F> >); requires std::is_constructible_v<std::decay_t<F>, F>; }' depends on itself
   10 | requires requires {
      | ^~~~~~~~~~
[...]
<snip>compressed_pair.h:129:22: note: while checking constraint satisfaction for template 'Callable<std::tuple<const Callable &>>' required here
```

But it's not true that this constraint depends upon itself. If you substitute in `std::tuple<const Callable &>` for `F`, you get:
  
```c++
requires(!std::is_same_v<Callable, std::decay_t<std::tuple<const Callable &>>>);
  
requires std::is_constructible_v<
    std::decay_t<std::tuple<const Callable &>>,
    std::tuple<const Callable &>>;
```

Neither of these should depend on anything to do with that constructor, as far as I can tell.

Note that clang [_does_ accept](https://godbolt.org/z/hs7s17zPs) this program if we don't use `-stdlib=libc++`. It's possible this is a bug in libc++, or it's just an accident of how the type traits are implemented in libc++, triggering a compiler bug that we don't see otherwise.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV0-T2rgT_TTi0hUK5DEeDhwGGPKbSyqHX9VWTlOy3cZKhORI7WHJYT_7VgvbmAyZna3sFGUGIfWf10-vGxWC3lvElUjXIt1OVEu186uvqnB5UJPclafV_9Aj6AAKgj40BqHxbu_VAY41f3NEKJwN5NuCQIFYzAKVInkQyUPV2oK0s2Ixg8q7AygolDEqNwh0ahCOmmpQQHhojCIsL5acn8L_axwvcAyFOzSKNBs4n7Un0LZpqQtGExTKQuFREX8K4I4WCteczgFQjd3-yvmj8qW2e_BYoUdb4FTMtmL20D0Xs_OrEHLNr_OqTLQtTFsiiGTTJ6iMSB5vbeAsn8krTeGyIz47wDY9HiLrPADAsCrkvZBLEMkWSqxUa0gk_bbRngjSaGHxy0NXthfgGvSKnBfJ9t-YuRjrK9fnatUBYTekyls8fm-1x3D55ypVACF3Qu7gD4TSWSEzgqOyBFTHel_KTw60JfRVZB1XnyJBmtMNa2Mijb_ug4jIzgem6vAc1AGfX0SyuQCwgWFDiYU6PZNINjG75FHI5Q08Bv9PBIc2EOQIjQshMpYcHNQ3BNf6Cy1dNSald4cbxi4bfqbqdVIwzmdAgH3HxH6VjNycSzZmici2N-m4i7RYQHU7f23pQqpI3u45bM22Px17cbqEyrme69kaXgtIstGWelOPUEVaDmFl67PZS9TD5R17-rjZgEjXqiiwoSBS5nxN1AR2FpHeuzJ3hqbO74Xc_RBy97moX758_7iIsUVK9uqnArwoo8szFcVi9iGGve3kQkbvcgN5S1AYZffs2-NXLCiApve5__Ljz8fF_efKsntFQL6136ANLFs3XAIvGJ2LZGt03gvXOY7hxlTOGHdkC-g93_2Hm7LXfUw2wbW-wEiQh_mMH3cieRgOQ1CkQ6VioZjOZ-IppoKQ2fjWjyTgt64fDPfvv6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