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

    <tr>
        <th>Summary</th>
        <td>
            Overloads based on constrains not properly working with modules
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            clang:modules
      </td>
    </tr>

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

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

<pre>
    Tested with
Debian clang version 16.0.0 (++20221226071857+aa171833ab00-1~exp1~20221226071956.509)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin


data.cppm
```
module;
#include <expected> 
#include <memory> 
export module data; 

export std::expected<std::unique_ptr<int>, int> parse() {
  return std::make_unique<int>(42); 
}
```
main.cpp
```
#include <expected> 
#include <memory> 
import data; 
 
int main(int argc, const char *argv[]) {                                        
 std::expected<std::unique_ptr<int>, int> result = parse(); 
}     
```
Fails to build with the following errors
```
In module 'data' imported from /data/src/test/main.cpp:3:
/usr/lib/llvm-16/bin/../include/c++/v1/__expected/expected.h:264:35: error: invalid reference to function '~__union_t': constraints not satisfied
  _LIBCPP_HIDE_FROM_ABI constexpr ~expected()
 ^
/data/src/test/main.cpp:6:53: note: in defaulted destructor for 'std::expected<std::unique_ptr<int>, int>' first required here
  std::expected<std::unique_ptr<int>, int> result = parse();
 ^
/usr/lib/llvm-16/bin/../include/c++/v1/__expected/expected.h:630:16: note: because 'is_trivially_destructible_v<std::unique_ptr<int> >' evaluated to false
      requires(is_trivially_destructible_v<_Tp> && is_trivially_destructible_v<_Err>)
 ^
/data/src/test/main.cpp:6:53: error: invalid reference to function '~expected': constraints not satisfied
 std::expected<std::unique_ptr<int>, int> result = parse();
 ^
/usr/lib/llvm-16/bin/../include/c++/v1/__expected/expected.h:265:14: note: because 'is_trivially_destructible_v<std::unique_ptr<int> >' evaluated to false
    requires(is_trivially_destructible_v<_Tp> && is_trivially_destructible_v<_Err>)
             ^
2 errors generated.
ninja: build stopped: subcommand failed.

```
Switching the order of the destructors of `_union_t` and `expected`  in libc++ "fixes" the issue.
So it seems only the first overload is considered. When not using modules this code works. It also works when the `std::unique_ptr` is changed to a `int*`. (Which is trivial so the constrains of the first overload are satisfied.)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV02P2zYQ_TX0ZbCCRNqSffDBHyt0gRYJmgDpTaDEkcWEIhWS8nov-9sLSvJHAqNJG6RFDcOQNKMZzntvhjR3Th404postoTSXdNz_Vn-0a8IpWSxn_HeN8auW2MF1x5npREv6_foPAp4lr4h8Z7Emz2WkmuoFNcHOKJ10mhI0iiOYiB0SeiW0C2NKU0oTeMsWS4yQrecJ1myZIyXcfyQvOKpS15vnFaLNFrEK0JXY5L33B7QE7aB0zIt0vlDVz0oqfvTw0H3k0tjkQtojUAVHDvj5Gk0PWnnuVIo9tIGE6F57yyheSn16HH7K7jnUdV17fQwjafvcNsa0SskbDtZKZO6Ur1AIGyHpw4rj4KwR7hnb7E19uVqxVNnrIcxJoTEhG3hdjGTh_OCsA1hm2uG3eVZr-XnHovOW8J2UnvCHgndwXgFHbcOByJWQLJp2QAWfW_1NXDLP2ExRrqJspzTwMF1Udn-Pipc6oDZXeOPYSTbAYEvwTnbtIeQmtBluOT2UIXKK6Odh6rhFgjdcHs4BoUv9hME8J2fKdUPYG_R9coDYftbGr6A8ybTV7DlXCoH3kDZSzV2HPgGoTZKmWepD4DWGuvuvvykz6oiNBuwoxmMUKKA2po2dMFoyJ2tCM09Ok9ofqGSbViocaJo6hgly_Crju1Dkk4dRPMoIjSfOCQ0r8amJzQ_JoTmRXFBjubny6ghbEPTeUizCE05FBMupD5yJQVYrNGirjBgUPe68mGyEJq9FkGoRhee0Cy8MfBtudTegTYeHPfS1RLFWezFr0_b3du3xS9P-8ci__3Nb8Vm-zS-hqfOwut1gcvLzAGyeLxU_w2kUsI2iwBXyI9jF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