public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor
@ 2022-08-13 10:23 egor.pugin at gmail dot com
  2022-08-13 11:42 ` [Bug libstdc++/106608] " egor.pugin at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: egor.pugin at gmail dot com @ 2022-08-13 10:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106608
           Summary: [12 Regression] std::optional requires unavailable
                    dtor
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egor.pugin at gmail dot com
  Target Milestone: ---

by John Preston

We've tried to build Telegram Desktop with GCC 12 and got such error:

http://paste.mva.name/co36VoGr.txt

There is a struct A { vector<B> b; }, where B is a declared, but not defined
struct:

https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/passport/passport_panel_edit_scans.h#L38

In the same header later in a method there is am argument of type optional<A>
with a default value nullopt:

https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/passport/passport_panel_edit_scans.h#L75

When I read the error text that the compiler gave me (link above) I see, that
it wants to instantiate this constructor:

constexpr std::_Optional_base<Passport::ScanListData, false,
false>::_Optional_base() = default;

and for that it tries to instantiate (why? what for?) this destructor method:

std::_Optional_payload<Passport::ScanListData, false, false,
false>::~_Optional_payload

Which of course it can't instantiate, because the destructor of ScanListData is
not available in that place of the code, this struct is not defined yet. But
why does it need this destructor? This constructor of optional(nullopt_t) never
calls this destructor.

All major compilers (MSVC, GCC, Clang) of all (tried) modern versions (in case
of GCC — before 12) build this code without problems. Is this a GCC regression?

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

* [Bug libstdc++/106608] [12 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
@ 2022-08-13 11:42 ` egor.pugin at gmail dot com
  2022-08-13 12:22 ` egor.pugin at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: egor.pugin at gmail dot com @ 2022-08-13 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Egor Pugin <egor.pugin at gmail dot com> ---
Update links.

===

We've tried to build Telegram Desktop with GCC 12 and got such error:

http://paste.mva.name/co36VoGr.txt

There is a struct A { vector<B> b; }, where B is a declared, but not defined
struct:

https://github.com/telegramdesktop/tdesktop/blob/d63e50944a7949ffffa0ecd5113d5ef82166eafc/Telegram/SourceFiles/passport/passport_panel_edit_scans.h#L28-L40

In the same header later in a method there is am argument of type optional<A>
with a default value nullopt:

https://github.com/telegramdesktop/tdesktop/blob/d63e50944a7949ffffa0ecd5113d5ef82166eafc/Telegram/SourceFiles/passport/passport_panel_edit_scans.h#L75-L77

When I read the error text that the compiler gave me (link above) I see, that
it wants to instantiate this constructor:

constexpr std::_Optional_base<Passport::ScanListData, false,
false>::_Optional_base() = default;

and for that it tries to instantiate (why? what for?) this destructor method:

std::_Optional_payload<Passport::ScanListData, false, false,
false>::~_Optional_payload

Which of course it can't instantiate, because the destructor of ScanListData is
not available in that place of the code, this struct is not defined yet. But
why does it need this destructor? This constructor of optional(nullopt_t) never
calls this destructor.

All major compilers (MSVC, GCC, Clang) of all (tried) modern versions (in case
of GCC — before 12) build this code without problems. Is this a GCC regression?

===

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

* [Bug libstdc++/106608] [12 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
  2022-08-13 11:42 ` [Bug libstdc++/106608] " egor.pugin at gmail dot com
@ 2022-08-13 12:22 ` egor.pugin at gmail dot com
  2022-08-14  8:22 ` egor.pugin at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: egor.pugin at gmail dot com @ 2022-08-13 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

Egor Pugin <egor.pugin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egor.pugin at gmail dot com

--- Comment #2 from Egor Pugin <egor.pugin at gmail dot com> ---
Created attachment 53450
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53450&action=edit
preprocessed repro

clang++-14 -std=gnu++20 file.cpp

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

* [Bug libstdc++/106608] [12 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
  2022-08-13 11:42 ` [Bug libstdc++/106608] " egor.pugin at gmail dot com
  2022-08-13 12:22 ` egor.pugin at gmail dot com
@ 2022-08-14  8:22 ` egor.pugin at gmail dot com
  2022-08-14 16:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: egor.pugin at gmail dot com @ 2022-08-14  8:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Egor Pugin <egor.pugin at gmail dot com> ---
Small repro https://godbolt.org/z/WKc7arxMs
Probably clang issue.

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

* [Bug libstdc++/106608] [12 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
                   ` (2 preceding siblings ...)
  2022-08-14  8:22 ` egor.pugin at gmail dot com
@ 2022-08-14 16:58 ` pinskia at gcc dot gnu.org
  2022-08-15  8:24 ` [Bug libstdc++/106608] [12/13 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-14 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 53453
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53453&action=edit
small testcase

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

* [Bug libstdc++/106608] [12/13 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
                   ` (3 preceding siblings ...)
  2022-08-14 16:58 ` pinskia at gcc dot gnu.org
@ 2022-08-15  8:24 ` rguenth at gcc dot gnu.org
  2023-03-27 14:10 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-15  8:24 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12 Regression]             |[12/13 Regression]
                   |std::optional requires      |std::optional requires
                   |unavailable dtor            |unavailable dtor
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid
   Target Milestone|---                         |12.2

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

* [Bug libstdc++/106608] [12/13 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
                   ` (4 preceding siblings ...)
  2022-08-15  8:24 ` [Bug libstdc++/106608] [12/13 " rguenth at gcc dot gnu.org
@ 2023-03-27 14:10 ` rguenth at gcc dot gnu.org
  2023-03-29  8:33 ` redi at gcc dot gnu.org
  2023-03-29  8:38 ` [Bug libstdc++/106608] std::optional requires unavailable dtor when compiled with clang redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-27 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-03-27
             Status|UNCONFIRMED                 |WAITING

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Trunk accepts the small testcase unless the commented line is uncommented, but
then even GCC 10 and GCC 11 reject the testcase.

So what is this bug about?

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

* [Bug libstdc++/106608] [12/13 Regression] std::optional requires unavailable dtor
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-27 14:10 ` rguenth at gcc dot gnu.org
@ 2023-03-29  8:33 ` redi at gcc dot gnu.org
  2023-03-29  8:38 ` [Bug libstdc++/106608] std::optional requires unavailable dtor when compiled with clang redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-29  8:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Egor Pugin from comment #1)
> All major compilers (MSVC, GCC, Clang) of all (tried) modern versions (in
> case of GCC — before 12) build this code without problems. Is this a GCC
> regression?

Your links clearly show you're compiling with Clang though, not GCC. The paste
starts with:
[1/135] /usr/lib/ccache/bin/clang++


The code can be reduced to:

template<class T>
struct vector
{
  T* ptr;
  vector();
  vector(const vector&);
  ~vector() { ++ptr; } // requires T to be complete
};

struct nullopt_t { };
constexpr nullopt_t nullopt{};

template<class T>
struct optional_payload
{
  optional_payload() = default;
  ~optional_payload() { if (engaged) value.~T(); }
  union {
    unsigned char dummy;
    T value;
  };
  bool engaged = false;
};

template<class T>
struct optional_base
{
  optional_base() = default;
  ~optional_base() = default;
  optional_payload<T> payload;
};

template<class T>
struct optional : optional_base<T>
{
  constexpr optional(nullopt_t) { }
};

struct ScanInfo;

struct List {
  List(optional<vector<ScanInfo>>&& = nullopt);
};

GCC compiles this, but Clang doesn't:

$ clang++ -std=c++17 -c inc.cc
inc.cc:36:13: error: call to implicitly-deleted default constructor of
'optional_base<vector<ScanInfo>>'
  constexpr optional(nullopt_t) { }
            ^
inc.cc:47:39: note: in instantiation of member function
'optional<vector<ScanInfo>>::optional' requested here
  List(optional<vector<ScanInfo>>&& = nullopt);
                                      ^
inc.cc:28:3: note: explicitly defaulted function was implicitly deleted here
  optional_base() = default;
  ^
inc.cc:30:23: note: default constructor of 'optional_base<vector<ScanInfo>>' is
implicitly deleted because field 'payload' has a deleted default constructor
  optional_payload<T> payload;
                      ^
inc.cc:16:3: note: explicitly defaulted function was implicitly deleted here
  optional_payload() = default;
  ^
inc.cc:20:7: note: default constructor of 'optional_payload<vector<ScanInfo>>'
is implicitly deleted because variant field 'value' has a non-trivial default
constructor
    T value;
      ^
1 error generated.


Neither does EDG:

$ edg --c++17 -c inc.cc
"inc.cc", line 36: error: the default constructor of
          "optional_base<vector<ScanInfo>>" cannot be referenced -- it is a
          deleted function
    constexpr optional(nullopt_t) { }
                                  ^
          detected during instantiation of "optional<T>::optional(nullopt_t)
                    [with T=vector<ScanInfo>]" at line 42

"inc.cc", line 7: error: expression must be a pointer to a complete object type
    ~vector() { ++ptr; } // requires T to be complete
                  ^
          detected during:
            instantiation of "vector<T>::~vector() [with T=ScanInfo]" at line
                      17
            instantiation of "optional_payload<T>::~optional_payload() [with
                      T=vector<ScanInfo>]" at line 43

2 errors detected in the compilation of "inc.cc".

Nor MSVC:

<source>(7): error C2036: 'ScanInfo *': unknown size
<source>(7): note: while compiling class template member function
'vector<ScanInfo>::~vector(void)'
<source>(44): note: see reference to function template instantiation
'vector<ScanInfo>::~vector(void)' being compiled
<source>(20): note: see reference to class template instantiation
'vector<ScanInfo>' being compiled
<source>(30): note: see reference to class template instantiation
'optional_payload<T>' being compiled
        with
        [
            T=vector<ScanInfo>
        ]
<source>(35): note: see reference to class template instantiation
'optional_base<T>' being compiled
        with
        [
            T=vector<ScanInfo>
        ]
<source>(42): note: see reference to class template instantiation
'optional<vector<ScanInfo>>' being compiled
Compiler returned: 2


Maybe the code is ill-formed (no diagnostic required), or maybe G++ is being
too generous to compile it, but I don't think there's a libstdc++ bug here.

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

* [Bug libstdc++/106608] std::optional requires unavailable dtor when compiled with clang
  2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
                   ` (6 preceding siblings ...)
  2023-03-29  8:33 ` redi at gcc dot gnu.org
@ 2023-03-29  8:38 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-29  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12/13 Regression]          |std::optional requires
                   |std::optional requires      |unavailable dtor when
                   |unavailable dtor            |compiled with clang
           Keywords|needs-bisection,            |
                   |rejects-valid               |
   Target Milestone|12.3                        |---

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also, there's no regression. I don't know why you think this has anything to do
with GCC 12. Given this code:

#include <optional>
#include <vector>
using namespace std;

struct ScanInfo;

struct List {
  List(optional<vector<ScanInfo>>&& = nullopt);
};

All versions of GCC compile it. Clang rejects it with all libstdc++ headers:


$ clang++ -std=c++17 -c inc.cc --gcc-toolchain=$HOME/gcc/8
In file included from inc.cc:2:
In file included from
/home/jwakely/gcc/8/lib/gcc/x86_64-pc-linux-gnu/8.5.0/../../../../include/c++/8.5.0/vector:62:
/home/jwakely/gcc/8/lib/gcc/x86_64-pc-linux-gnu/8.5.0/../../../../include/c++/8.5.0/bits/stl_construct.h:133:7:
error: static assertion failed due to requirement
'is_destructible<ScanInfo>::value': value type is destructible


$ clang++ -std=c++17 -c inc.cc --gcc-toolchain=$HOME/gcc/9
In file included from inc.cc:2:
In file included from
/home/jwakely/gcc/9/lib/gcc/x86_64-pc-linux-gnu/9.5.0/../../../../include/c++/9.5.0/vector:65:
/home/jwakely/gcc/9/lib/gcc/x86_64-pc-linux-gnu/9.5.0/../../../../include/c++/9.5.0/bits/stl_construct.h:133:7:
error: static assertion failed due to requirement
'is_destructible<ScanInfo>::value': value type is destructible


$ clang++ -std=c++17 -c inc.cc --gcc-toolchain=$HOME/gcc/10
In file included from inc.cc:1:
In file included from
/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.4.1/../../../../include/c++/10.4.1/optional:36:
In file included from
/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.4.1/../../../../include/c++/10.4.1/utility:70:
In file included from
/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.4.1/../../../../include/c++/10.4.1/bits/stl_pair.h:59:
In file included from
/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.4.1/../../../../include/c++/10.4.1/bits/move.h:57:
/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.4.1/../../../../include/c++/10.4.1/type_traits:844:7:
error: static assertion failed due to requirement
'std::__is_complete_or_unbounded(std::__type_identity<ScanInfo>{})': template
argument must be a complete class or an unbounded array


$ clang++ -std=c++17 -c inc.cc --gcc-toolchain=$HOME/gcc/11
In file included from inc.cc:1:
In file included from
/home/jwakely/gcc/11/lib/gcc/x86_64-pc-linux-gnu/11.3.1/../../../../include/c++/11.3.1/optional:36:
In file included from
/home/jwakely/gcc/11/lib/gcc/x86_64-pc-linux-gnu/11.3.1/../../../../include/c++/11.3.1/utility:70:
In file included from
/home/jwakely/gcc/11/lib/gcc/x86_64-pc-linux-gnu/11.3.1/../../../../include/c++/11.3.1/bits/stl_pair.h:59:
In file included from
/home/jwakely/gcc/11/lib/gcc/x86_64-pc-linux-gnu/11.3.1/../../../../include/c++/11.3.1/bits/move.h:57:
/home/jwakely/gcc/11/lib/gcc/x86_64-pc-linux-gnu/11.3.1/../../../../include/c++/11.3.1/type_traits:885:7:
error: static assertion failed due to requirement
'std::__is_complete_or_unbounded(std::__type_identity<ScanInfo>{})': template
argument must be a complete class or an unbounded array


$ clang++ -std=c++17 -c inc.cc --gcc-toolchain=$HOME/gcc/12
In file included from inc.cc:1:
In file included from
/home/jwakely/gcc/12/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/optional:37:
/home/jwakely/gcc/12/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/type_traits:910:7:
error: static assertion failed due to requirement
'std::__is_complete_or_unbounded(std::__type_identity<ScanInfo>{})': template
argument must be a complete class or an unbounded array

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

end of thread, other threads:[~2023-03-29  8:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-13 10:23 [Bug libstdc++/106608] New: [12 Regression] std::optional requires unavailable dtor egor.pugin at gmail dot com
2022-08-13 11:42 ` [Bug libstdc++/106608] " egor.pugin at gmail dot com
2022-08-13 12:22 ` egor.pugin at gmail dot com
2022-08-14  8:22 ` egor.pugin at gmail dot com
2022-08-14 16:58 ` pinskia at gcc dot gnu.org
2022-08-15  8:24 ` [Bug libstdc++/106608] [12/13 " rguenth at gcc dot gnu.org
2023-03-27 14:10 ` rguenth at gcc dot gnu.org
2023-03-29  8:33 ` redi at gcc dot gnu.org
2023-03-29  8:38 ` [Bug libstdc++/106608] std::optional requires unavailable dtor when compiled with clang redi 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).