<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJztWVmPozgQ_jXkxQoikPMhD-l0R9vSzrzNat-QAZN41zFZ2_Qxv36rzBEgZx-ZlVYdEYKDj6qvvjowUZa8zh8lN5wK8UoeSRZppp5YQsyGEaZUpgjVhBJn7G0zkfQHrud60CBRzkVCUspFrhjJJPaIBZXr_iDA-88bHm9Irpkm6zjuD3zHn2jsJHikTRI7_h0eY88lvzGYgeMqmWREcDgptlNZksdMOcHC8e4drzqPveKoJij-9QMuY5EnjDjB8okqTqVxgoejd1lsMrW_ac8gES4ULOqxy_1f5YClyOQaxhH8PjnBXUeijpil1hVUmnBDUtDN8ZddrBBFfUrRSochcfyV2e7gXAG6iriEcwkF6VuR78um75F-TAzdcTeOj0xSC_COaVaABhzfH_9EHOGoZLLs8Fcl3PtJ4aq-WUO8GIJ2wcKHb0E1vKDGsO3OEJMheYATCRPMACHTXMaGZ7KQgZSf8I9itlCDjegalpxyGe4EjVnIZcJeQrRl-H1npVyScKHW2vHHcLiuS8KQ2vasPaszevhkVSfDCSqMGsrMMPzlEg5t4D6nqBjJ0lpJgiAIahjROxaDc_KfRR_0ooqYYZgwA9SpWvvVsNkFJlimVGhLv5PUtseJ0d6P3636E3DOf3Km0SYb8NwOcqBYeEdxnWkY8tZqaaaeqUrQHtYKONu0tgCY48AOt7EEEm72H1giQljOBJZD9MsR10BvgW-N63oCTmSnmRFncgff-1uTfjD0AkT8EtZbto2Y2kP-y6A9i2i1kj-1kAX3EIpSmgtTh_4OblWQBMVR7aDr7eVwWKq8InEGUKgcZSXgHS3Fr8hEJSlSrrSxinDV0uMDWY1c-nw-W4beoEsW9rITPOYGSpM9eDVNnqEy4dtGjyJRHHjG5KGwesLjMJeYQq426ScqhxEn8JraJaw2PjgBWLIr5mXT86MIRCymmDzL5YEgDGo1XOBbaMmCQze2rpOZ7BvFnyCwNeRpYhH-kLwoEPlPZoP3yk4BdKmnu4o1NwB16lWMeV_9UFOjVUB00tDnyz0aTbHu8Zybx8V3Jf-jqJyLlLnmcl2m_WL94vI0K77S-lda_0rrX2n9K63_f9K6XyRhTdZMMgWhNXHP7JA8Vpka95oyojeKy79Jkj1LsrO7PzHTGmnBBcMO7MUoGqNvbXfwlyIJT1OghIyZS769gp9oa_ArdosKOCCsWvBtyMDQWelqibW_VRYE9XYPxNfqus4hAJ953TFJtwwBtGYmHbMfLHGMu6W3a9schCFYMyztGDbsCI_N3eGzppCkrdyBQZtK1Gi0M35T3BM1UtDp0GQ4lxWV8jetetW-Gu6ZgRvW22jY3lCZCCxD9rw4RYZP2VH7vE21eqZGO1iMMa60t8YgJgH5MRYQZNvx0FIAj5EgR_eB_GT7gvNwg4EXyKUbVfDtmXhd8GjpPsCM4V_cLKvdD1DX-hIcxyuC65j7JulHKPyknRFSG2sLsS_ICbEfxpHa1DmoLOx2fCwyW2hDL3QlOH8sCr3RKFj8-KP3PGxddvYP8-NE0m0_wZxPq810mu9TadXtMI3egDtIm8H4jdVEizu3rBvOJ5VTCl5bF_SSeZDMghnt0dxsMjU3Kkt5L1divjFmZ1-QQN0GwZqbTR654CHQEOKp-ulD1fAXSIjlm9Y5xq7VyJ-Nxr3NnKVRNAmioU-Hns-SgA5TfwCr0SljfpSMeoJGTOi5M4L47Ev2TOwUcO2M7nsfl4DPfc_3vYHnD8bDyXDo0hGdpjOoH2fjJBhT6gw9toUHIhfncTO17qm5nTLK1xpuCq6N3t-EgMfXkjErMEhowOJsXqWf4o0SumVZLpH2Wzd8FXfVU0RJLfuY9Qa371nt51b1fwF1kGWM>52956</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
        </td>
    </tr>

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

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

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

<pre>
    Initially I observed the error as a `mold-1.0.0` build failure on `clang-13` which uses gcc-12's `libstdc++`. Here is a one line reproducer:

```c++
#include <variant>
#include <vector>

std::variant<std::vector<long> > v;
```

`gcc-12` builds it fine, `clang-13` fails:

```
$ /tmp/gcc-12/bin/c++ -std=c++20 -c tapi.cc
$ /tmp/clang-13/bin/c++ -std=c++20 -c tapi.cc
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:460:2: error: attempt to use a deleted function
        _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
        ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:747:4: note: in instantiation of function template specialization 'std::__detail::__variant::_Variant_storage<false, std::vector<long>>::_Variant_storage<0UL>' requested here
        : _Base(__i, std::forward<_Args>(__args)...)
          ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:742:9: note: in instantiation of function template specialization 'std::__detail::__variant::_Variant_base<std::vector<long>>::_Variant_base<0UL>' requested here
      : _Variant_base(in_place_index<0>) { }
        ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:1403:7: note: in instantiation of member function 'std::__detail::__variant::_Variant_base<std::vector<long>>::_Variant_base' requested here
      variant() = default;
      ^
tapi.cc:13:34: note: in defaulted default constructor for 'std::variant<std::vector<long>>' first required here
std::variant<std::vector<long> > v;
                                 ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:401:7: note: explicitly defaulted function was implicitly deleted here
      ~_Variadic_union() = default;
      ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:409:30: note: destructor of '_Variadic_union<std::vector<long>>' is implicitly deleted because variant field '_M_first' has a non-trivial destructor
      _Uninitialized<_First> _M_first;
                             ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:480:7: error: attempt to use a deleted function
      ~_Variant_storage()
      ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:558:20: note: in instantiation of member function 'std::__detail::__variant::_Variant_storage<false, std::vector<long>>::~_Variant_storage' requested here
      using _Base::_Base;
                   ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:742:9: note: in instantiation of function template specialization 'std::__detail::__variant::_Variant_base<std::vector<long>>::_Variant_base<0UL>' requested here
      : _Variant_base(in_place_index<0>) { }
        ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:1403:7: note: in instantiation of member function 'std::__detail::__variant::_Variant_base<std::vector<long>>::_Variant_base' requested here
      variant() = default;
      ^
tapi.cc:13:34: note: in defaulted default constructor for 'std::variant<std::vector<long>>' first required here
std::variant<std::vector<long> > v;
                                 ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:401:7: note: explicitly defaulted function was implicitly deleted here
      ~_Variadic_union() = default;
      ^
/<<NIX>>/gcc-12.0.0/include/c++/12.0.0/variant:409:30: note: destructor of '_Variadic_union<std::vector<long>>' is implicitly deleted because variant field '_M_first' has a non-trivial destructor
      _Uninitialized<_First> _M_first;
                             ^
2 errors generated.
```

I attempted to shrink down preprocessed file to extract compiler difference. My result:

```c++
struct _Vector_base {
  ~_Vector_base();
};
template <typename> union _Variadic_union {
  ~_Variadic_union() requires(!__has_trivial_destructor(_Variadic_union));
  _Vector_base _M_first;
};
struct _Variant_storage {
  _Variant_storage();
  _Variadic_union<int> _M_u;
};
struct _Variant_storage v;
```

`gcc` / `clang` handling difference:

```
$ /tmp/gcc-12/bin/c++ -std=c++20 -c tapi.cc.cc
$ /tmp/clang-13/bin/c++ -std=c++20 -c tapi.cc.cc
tapi.cc.cc:6:32: error: incomplete type '_Variadic_union<int>' used in type trait expression
  ~_Variadic_union() requires(!__has_trivial_destructor(_Variadic_union));
                               ^
tapi.cc.cc:11:24: note: in instantiation of template class '_Variadic_union<int>' requested here
  _Variadic_union<int> _M_u;
                       ^
tapi.cc.cc:5:27: note: definition of '_Variadic_union<int>' is not complete until the closing '}'
template <typename> union _Variadic_union {
                          ^
tapi.cc.cc:13:25: error: attempt to use a deleted function
struct _Variant_storage v;
                        ^
tapi.cc.cc:11:24: note: destructor of '_Variant_storage' is implicitly deleted because field '_M_u' has a deleted destructor
  _Variadic_union<int> _M_u;
                       ^
tapi.cc.cc:7:16: note: destructor of '_Variadic_union<int>' is implicitly deleted because variant field '_M_first' has a non-trivial destructor
  _Vector_base _M_first;
               ^
2 errors generated.
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWcmO4zYQ_Rr5QljQ4vXgg9vdRhrIzG2C3ARKomwmNOWQVC_z9amiFlvy2osnQNCGLIsWl6pXrxZRcZ6-zh4lN5wK8UoeSR5rpp5YSsyaEaZUrgjVhBJn5G1ykfZ913M9aJC44CIlGeWiUIzkEnskgspV3w_x_vOaJ2tSaKbJKkn6fuAEY42dBI-1SRMnuMNj5LnkNwYzcFwll4wIDifFtipPi4QpJ5w73r3j1eeRVx71BOW_QchlIoqUESdcPFHFqTRO-HD0LktMrnY37RkkwoXCeTN2sfurGrAQuVzBOILfJye860jUEbPSuoZKE25IBro5waKLFaKoTyla6zAgTrA0my2ca0CXMZdwrqAgfSvyfdUMPNJPiKFb7ibJkUkaAd4xzRLQgOP745-IIxy1TJYdwbKCezcpXDU3G4jnA9AunAfwLamGF9QYttkaYnIkD3AiZYIZIGRWyMTwXJYykOoT_VHOFmmwEV3BkhMuo62gCYu4TNlLhLaMvm-tlAsSzdVKO8EIDtd1SRRR2562Z3WGD5-s6ngwRoVRQ5kbhr9cwqEN3OcUFSN51ihJEARBDSN6yxJwTv6z7INeVBMzilJmgDp1a7caNrvAhIuMCm3pd5La9jgx2vvxu1V_DM75T8E02mQNnttBDhSL7iiuM4ki3loty9UzVSnaw1oBZ5s0FgBzHNjhNpZAwk3_A0vECMuZwHKIfjXiGugt8K1xXU_Aiew0U-KM7-B7f2vS-wMvRMQvYb1hm5ipHeS_DNqziNYrBRMLWXgPoSijhTBN6O_gVgdJUBzVDrveXg2HpaorkuQAhSpQVgLe0VL8ikxUkSLjShurCFctPT6Q1cilz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