public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
@ 2022-01-02 21:40 slyfox at gcc dot gnu.org
  2022-01-02 21:59 ` [Bug libstdc++/103891] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: slyfox at gcc dot gnu.org @ 2022-01-02 21:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

            Bug ID: 103891
           Summary: clang-13 fails to compile libstdc++'s
                    std::variant<std::vector<int>>: error: attempt to use
                    a deleted function
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

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:

    #include <variant>
    #include <vector>

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

$ /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;
      ^
...


I attempted to reduce it down to something manageable but ended up with
something else: https://github.com/llvm/llvm-project/issues/52956

I don't really understand how requires() works.

Should libstdc++ work as is against clang++? Does it perhaps need a small
tweak?

Thank you!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
@ 2022-01-02 21:59 ` pinskia at gcc dot gnu.org
  2022-01-03 15:55 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-02 21:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Should libstdc++ work as is against clang++? Does it perhaps need a small tweak?

it depends, It might be the case that clang does not implement all of C++20
that GCC implements either.


There is also PR 79424 which might be related to your reduced testcase.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
  2022-01-02 21:59 ` [Bug libstdc++/103891] " pinskia at gcc dot gnu.org
@ 2022-01-03 15:55 ` ppalka at gcc dot gnu.org
  2022-01-04 10:07 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-03 15:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Further reduction:

template<typename _First>
union _Variadic_union {
  ~_Variadic_union() = default;
  ~_Variadic_union() requires true { }
  _First _M_first;
};
struct vector {
  ~vector();
};
_Variadic_union<vector> v;

Which Clang rejects with:

103891.ii:10:25: error: attempt to use a deleted function
_Variadic_union<vector> v;
                        ^
103891.ii:3:3: note: explicitly defaulted function was implicitly deleted here
  ~_Variadic_union() = default;
  ^
103891.ii:5:10: note: destructor of '_Variadic_union<vector>' is implicitly
deleted because variant field '_M_first' has a non-trivial destructor
  _First _M_first;
         ^

So it looks like Clang is selecting the less specialized defaulted destructor,
which doesn't seem correct.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
  2022-01-02 21:59 ` [Bug libstdc++/103891] " pinskia at gcc dot gnu.org
  2022-01-03 15:55 ` ppalka at gcc dot gnu.org
@ 2022-01-04 10:07 ` redi at gcc dot gnu.org
  2022-01-04 10:17 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-04 10:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |MOVED
           See Also|                            |https://github.com/llvm/llv
                   |                            |m-project/issues/45614

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a known bug (or unfinished feature) in Clang.

https://github.com/llvm/llvm-project/issues/45614

We're not going to work around it in libstdc++ because there is no feature test
macro that allows us to detect whether clang supports it, see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2493r0.html for
details.

If/when GCC bumps the value of __cpp_concepts we can use that to make C++20
support in std::variant conditional on compiler support.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-01-04 10:07 ` redi at gcc dot gnu.org
@ 2022-01-04 10:17 ` redi at gcc dot gnu.org
  2022-01-09  9:10 ` slyfox at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-04 10:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I suppose we could just do:

--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -54,7 +54,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION

-#if __cplusplus >= 202002L && __cpp_concepts
+#if __cplusplus >= 202002L && __cpp_concepts && __GNUC__ >= 12
 // P2231R1 constexpr needs constexpr unions and constrained destructors.
 # define __cpp_lib_variant 202106L
 #else

And then improve it later if GCC updates __cpp_concepts

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-01-04 10:17 ` redi at gcc dot gnu.org
@ 2022-01-09  9:10 ` slyfox at gcc dot gnu.org
  2022-01-11 13:24 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: slyfox at gcc dot gnu.org @ 2022-01-09  9:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #5 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> I suppose we could just do:
> 
> --- a/libstdc++-v3/include/std/variant
> +++ b/libstdc++-v3/include/std/variant
> @@ -54,7 +54,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
>  {
>  _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  
> -#if __cplusplus >= 202002L && __cpp_concepts
> +#if __cplusplus >= 202002L && __cpp_concepts && __GNUC__ >= 12
>  // P2231R1 constexpr needs constexpr unions and constrained destructors.
>  # define __cpp_lib_variant 202106L
>  #else
> 
> And then improve it later if GCC updates __cpp_concepts

That almost works:

In file included from bug.cc:12:
stdc++-include/c++/12.0.0/variant:300:18: error: no template named
'__aligned_membuf' in namespace '__gnu_cxx'
      __gnu_cxx::__aligned_membuf<_Type> _M_storage;
      ~~~~~~~~~~~^

On clang it also needs `#include <ext/aligned_buffer.h>` as well.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-01-09  9:10 ` slyfox at gcc dot gnu.org
@ 2022-01-11 13:24 ` cvs-commit at gcc dot gnu.org
  2022-01-11 13:32 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-11 13:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:5b417b35824fb5c15e3ee958cb86436b3409ebea

commit r12-6439-g5b417b35824fb5c15e3ee958cb86436b3409ebea
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jan 10 17:28:19 2022 +0000

    libstdc++: Make std::variant work with Clang in C++20 mode [PR103891]

    Clang has some bugs with destructors that use constraints to be
    conditionally trivial, so disable the P2231R1 constexpr changes to
    std::variant unless the compiler is GCC 12 or later.

    If/when P2493R0 gets accepted and implemented by G++ we can remove the
    __GNUC__ check and use __cpp_concepts >= 202002 instead.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103891
            * include/bits/c++config
(_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
            Define.
            * include/std/variant (__cpp_lib_variant): Only define C++20
            value when the compiler is known to support conditionally
            trivial destructors.
            * include/std/version (__cpp_lib_variant): Likewise.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-01-11 13:24 ` cvs-commit at gcc dot gnu.org
@ 2022-01-11 13:32 ` redi at gcc dot gnu.org
  2022-01-11 16:27 ` slyfox at gcc dot gnu.org
  2022-02-14 13:06 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-11 13:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|MOVED                       |FIXED
   Target Milestone|---                         |12.0

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for trunk with a workaround to disable the new constexpr stuff in
std::variant when not using GCC.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-01-11 13:32 ` redi at gcc dot gnu.org
@ 2022-01-11 16:27 ` slyfox at gcc dot gnu.org
  2022-02-14 13:06 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: slyfox at gcc dot gnu.org @ 2022-01-11 16:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #8 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
That allowed me to build mold-1.0.0 with clang-13 + libstdc++. Thank you!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/103891] clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function
  2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-01-11 16:27 ` slyfox at gcc dot gnu.org
@ 2022-02-14 13:06 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-14 13:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103891

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:164a761a9f4798dc69ecab80097807636dc17d61

commit r12-7227-g164a761a9f4798dc69ecab80097807636dc17d61
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Feb 14 12:46:10 2022 +0000

    libstdc++: Use __cpp_concepts instead of custom macro [PR103891]

    With the new value of __cpp_concepts required by P2493, we can test
    whether the compiler supports conditionally trivial special members.
    This allows us to remove the workaround that disables fully-constexpr
    std::variant for Clang. Now it should work for non-GCC compilers (such
    as future releases of Clang) that support conditionally trivial
    destructors and define the new value of __cpp_concepts.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103891
            * include/bits/c++config
(_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
            Remove.
            * include/std/variant: Check feature test macros instead.
            * include/std/version: Likewise.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-14 13:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-02 21:40 [Bug libstdc++/103891] New: clang-13 fails to compile libstdc++'s std::variant<std::vector<int>>: error: attempt to use a deleted function slyfox at gcc dot gnu.org
2022-01-02 21:59 ` [Bug libstdc++/103891] " pinskia at gcc dot gnu.org
2022-01-03 15:55 ` ppalka at gcc dot gnu.org
2022-01-04 10:07 ` redi at gcc dot gnu.org
2022-01-04 10:17 ` redi at gcc dot gnu.org
2022-01-09  9:10 ` slyfox at gcc dot gnu.org
2022-01-11 13:24 ` cvs-commit at gcc dot gnu.org
2022-01-11 13:32 ` redi at gcc dot gnu.org
2022-01-11 16:27 ` slyfox at gcc dot gnu.org
2022-02-14 13:06 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).