public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
@ 2021-05-19  8:00 piotrwn1 at gmail dot com
  2021-05-19  9:09 ` [Bug libstdc++/100667] [11/12 Regression] " redi at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: piotrwn1 at gmail dot com @ 2021-05-19  8:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100667
           Summary: std::tuple<A&&> cannot be constructed from A&&, if A
                    not defined (only forward declared)
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: piotrwn1 at gmail dot com
  Target Milestone: ---

The following code stops working when switching from gcc10 to gcc11 (gcc11.1
and trunk too) (both c++17 and c++20):


#include <utility>
#include <tuple>

class A;

std::tuple<A&&> foo(A&& a) {
    return std::tuple<A&&>(std::move(a));
}

It looks that std library code start requiring this to pass:
std::is_nothrow_constructible<A&&, A>...

Actually - I got this error when using gmock library (MOCK_METHOD), then I
extracted the problem to get SSCCE. 

Error logs (https://godbolt.org/z/TqMar3Tn6):

In file included from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/move.h:57,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/stl_pair.h:59,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/utility:70,
                 from <source>:1:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits: In
instantiation of 'struct std::is_nothrow_constructible<A&&, A>':
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:133:12:  
required from 'struct std::__and_<std::is_nothrow_constructible<A&&, A> >'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:649:66:   required
from 'static constexpr bool std::tuple<_Elements>::__nothrow_constructible()
[with _UElements = {A}; _Elements = {A&&}]'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   required
from 'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements
= {A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]'
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:971:25: error:
invalid use of incomplete type 'class A'
  971 |       = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:4:7: note: forward declaration of 'class A'
    4 | class A;
      |       ^
In file included from <source>:2:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple: In instantiation of
'static constexpr bool std::tuple<_Elements>::__nothrow_constructible() [with
_UElements = {A}; _Elements = {A&&}]':
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   required
from 'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements
= {A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]'
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:649:73: error:
'value' is not a member of 'std::__and_<std::is_nothrow_constructible<A&&, A>
>'
  649 |             __and_<is_nothrow_constructible<_Elements,
_UElements>...>::value;
      |                                                                        
^~~~~
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple: In instantiation of
'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements =
{A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]':
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   in
'constexpr' expansion of 'std::tuple<A&&>::__nothrow_constructible<A>()'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:732:9: error:
'constexpr' call flows off the end of the function
  732 |         tuple(_UElements&&... __elements)
      |         ^~~~~
ASM generation compiler returned: 1
In file included from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/move.h:57,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/stl_pair.h:59,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/utility:70,
                 from <source>:1:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits: In
instantiation of 'struct std::is_nothrow_constructible<A&&, A>':
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:133:12:  
required from 'struct std::__and_<std::is_nothrow_constructible<A&&, A> >'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:649:66:   required
from 'static constexpr bool std::tuple<_Elements>::__nothrow_constructible()
[with _UElements = {A}; _Elements = {A&&}]'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   required
from 'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements
= {A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]'
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:971:25: error:
invalid use of incomplete type 'class A'
  971 |       = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:4:7: note: forward declaration of 'class A'
    4 | class A;
      |       ^
In file included from <source>:2:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple: In instantiation of
'static constexpr bool std::tuple<_Elements>::__nothrow_constructible() [with
_UElements = {A}; _Elements = {A&&}]':
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   required
from 'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements
= {A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]'
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:649:73: error:
'value' is not a member of 'std::__and_<std::is_nothrow_constructible<A&&, A>
>'
  649 |             __and_<is_nothrow_constructible<_Elements,
_UElements>...>::value;
      |                                                                        
^~~~~
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple: In instantiation of
'constexpr std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements =
{A}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_implicitly_constructible<_UElements
...>(), bool>::type <anonymous> = true; _Elements = {A&&}]':
<source>:7:40:   required from here
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:733:49:   in
'constexpr' expansion of 'std::tuple<A&&>::__nothrow_constructible<A>()'
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:732:9: error:
'constexpr' call flows off the end of the function
  732 |         tuple(_UElements&&... __elements)
      |         ^~~~~
Execution build compiler returned: 1

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

* [Bug libstdc++/100667] [11/12 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
@ 2021-05-19  9:09 ` redi at gcc dot gnu.org
  2021-06-18  7:56 ` ostash at ostash dot kiev.ua
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-19  9:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Priority|P3                          |P2
           Keywords|                            |rejects-valid
            Summary|std::tuple<A&&> cannot be   |[11/12 Regression]
                   |constructed from A&&, if A  |std::tuple<A&&> cannot be
                   |not defined (only forward   |constructed from A&&, if A
                   |declared)                   |not defined (only forward
                   |                            |declared)
   Target Milestone|---                         |11.2
   Last reconfirmed|                            |2021-05-19
      Known to work|                            |10.3.0

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

* [Bug libstdc++/100667] [11/12 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
  2021-05-19  9:09 ` [Bug libstdc++/100667] [11/12 Regression] " redi at gcc dot gnu.org
@ 2021-06-18  7:56 ` ostash at ostash dot kiev.ua
  2021-07-28  7:07 ` rguenth at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ostash at ostash dot kiev.ua @ 2021-06-18  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

Viktor Ostashevskyi <ostash at ostash dot kiev.ua> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ostash at ostash dot kiev.ua

--- Comment #1 from Viktor Ostashevskyi <ostash at ostash dot kiev.ua> ---
Hello,

I have another example, but probably related:


#include <tuple>
#include <string>

class Foo{};

std::tuple<std::string, Foo> bar()
{
    return { {}, Foo{}};
}


Fails starting from GCC 11.1 in C++11/14/17/20 modes with the following error:

<source>: In function 'std::tuple<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >, Foo> bar()':
<source>:8:23: error: conversion from '<brace-enclosed initializer list>' to
'std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, Foo>' is ambiguous
    8 |     return { {}, Foo{}};
      |                       ^
In file included from <source>:1:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:1144:9: note:
candidate: 'std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&)
[with _Alloc = Foo; typename
std::enable_if<std::_TupleConstraints<std::is_object<_Alloc>::value, _T1,
_T2>::__is_implicitly_default_constructible(), bool>::type <anonymous> = true;
_T1 = std::__cxx11::basic_string<char>; _T2 = Foo]'
 1144 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/tuple:1052:9: note:
candidate: 'constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with
bool _Dummy = true; typename std::enable_if<std::_TupleConstraints<_Dummy, _T1,
_T2>::__is_implicitly_constructible<const _T1&, const _T2&>(), bool>::type
<anonymous> = true; _T1 = std::__cxx11::basic_string<char>; _T2 = Foo]'
 1052 |         tuple(const _T1& __a1, const _T2& __a2)
      |

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

* [Bug libstdc++/100667] [11/12 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
  2021-05-19  9:09 ` [Bug libstdc++/100667] [11/12 Regression] " redi at gcc dot gnu.org
  2021-06-18  7:56 ` ostash at ostash dot kiev.ua
@ 2021-07-28  7:07 ` rguenth at gcc dot gnu.org
  2022-04-21  7:49 ` rguenth at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28  7:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.2                        |11.3

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.2 is being released, retargeting bugs to GCC 11.3

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

* [Bug libstdc++/100667] [11/12 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (2 preceding siblings ...)
  2021-07-28  7:07 ` rguenth at gcc dot gnu.org
@ 2022-04-21  7:49 ` rguenth at gcc dot gnu.org
  2023-05-29 10:05 ` [Bug libstdc++/100667] [11/12/13/14 " jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.3                        |11.4

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-04-21  7:49 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:05 ` jakub at gcc dot gnu.org
  2023-05-29 11:16 ` piotrwn1 at gmail dot com
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |11.5

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-05-29 10:05 ` [Bug libstdc++/100667] [11/12/13/14 " jakub at gcc dot gnu.org
@ 2023-05-29 11:16 ` piotrwn1 at gmail dot com
  2024-03-27 12:59 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: piotrwn1 at gmail dot com @ 2023-05-29 11:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Piotr Nycz <piotrwn1 at gmail dot com> ---
It also fails on gcc12, gcc13 and trunk

pon., 29 maj 2023 o 12:09 jakub at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
napisał(a):

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100667
>
> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>    Target Milestone|11.4                        |11.5
>
> --- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> GCC 11.4 is being released, retargeting bugs to GCC 11.5.
>
> --
> You are receiving this mail because:
> You reported the bug.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-05-29 11:16 ` piotrwn1 at gmail dot com
@ 2024-03-27 12:59 ` redi at gcc dot gnu.org
  2024-03-27 13:36 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Piotr Nycz from comment #0)
> It looks that std library code start requiring this to pass:
> std::is_nothrow_constructible<A&&, A>...

Indeed, that's what the standard requires (Clang and MSVC reject this the same
way). The standard also says that using traits like is_constructible requires
complete types.

However, that's clearly silly for is_constructible<A&&, A> because we know that
reference binding is valid for any A whether it's complete or not.

This is the subject of:
https://cplusplus.github.io/LWG/issue2939

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (6 preceding siblings ...)
  2024-03-27 12:59 ` redi at gcc dot gnu.org
@ 2024-03-27 13:36 ` redi at gcc dot gnu.org
  2024-03-27 14:02 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Viktor Ostashevskyi from comment #1)
> I have another example, but probably related:

No, this is a completely different problem. See Bug 102257

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (7 preceding siblings ...)
  2024-03-27 13:36 ` redi at gcc dot gnu.org
@ 2024-03-27 14:02 ` redi at gcc dot gnu.org
  2024-03-27 14:03 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 14:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> (In reply to Piotr Nycz from comment #0)
> > It looks that std library code start requiring this to pass:
> > std::is_nothrow_constructible<A&&, A>...
> 
> Indeed, that's what the standard requires (Clang and MSVC reject this the
> same way). The standard also says that using traits like is_constructible
> requires complete types.
> 
> However, that's clearly silly for is_constructible<A&&, A> because we know
> that reference binding is valid for any A whether it's complete or not.
> 
> This is the subject of:
> https://cplusplus.github.io/LWG/issue2939

We can fix this in std::tuple by adding && to the source objects in all
is_constructible and is_convertible conditions. Or we could fix it in the type
traits themselves.

But I think it would be best to fix it in the compiler, so that we always allow
directly binding T&& or const T& to T, even if T is incomplete. Otherwise we'll
be playing whackamole all over the library.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (8 preceding siblings ...)
  2024-03-27 14:02 ` redi at gcc dot gnu.org
@ 2024-03-27 14:03 ` redi at gcc dot gnu.org
  2024-03-27 14:14 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The changes in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1285r0.pdf mean that
it's only undefined if the result of is_constructible_v<T&&, T> would change
were T completed. So there's no benefit to enforcing the completeness
requirement here, it's not UB anyway.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (9 preceding siblings ...)
  2024-03-27 14:03 ` redi at gcc dot gnu.org
@ 2024-03-27 14:14 ` redi at gcc dot gnu.org
  2024-03-27 17:44 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oh interestingly __is_constructible(Incomplete&&, Incomplete) is already
allowed, but __is_nothrow_constructible and __is_convertible give errors:


__is_nothrow_constructible(Incomplete&&, Incomplete)

<stdin>: In function ‘int main()’:
<stdin>:117:68: error: invalid use of incomplete type ‘struct Incomplete’
[-fpermissive]
<stdin>:110:8: note: forward declaration of ‘struct Incomplete’

__is_convertible(Incomplete, Incomplete&&)

<stdin>: In function ‘int main()’:
<stdin>:117:58: error: invalid use of incomplete type ‘struct Incomplete’
[-fpermissive]
<stdin>:110:8: note: forward declaration of ‘struct Incomplete’

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (10 preceding siblings ...)
  2024-03-27 14:14 ` redi at gcc dot gnu.org
@ 2024-03-27 17:44 ` redi at gcc dot gnu.org
  2024-03-28 18:26 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-27 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #8)
> But I think it would be best to fix it in the compiler, so that we always
> allow directly binding T&& or const T& to T, even if T is incomplete.
> Otherwise we'll be playing whackamole all over the library.

Actually the workarounds would only be needed in <type_traits>:

--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1187,6 +1187,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        "template argument must be a complete class or an unbounded array");
     };

+  template<typename _Tp, typename _Up>
+    struct is_nothrow_constructible<_Tp&, _Up>
+    : __is_nothrow_constructible_impl<_Tp&, __add_rval_ref_t<_Up>>
+    { };
+
+  template<typename _Tp, typename _Up>
+    struct is_nothrow_constructible<_Tp&&, _Up>
+    : __is_nothrow_constructible_impl<_Tp&&, __add_rval_ref_t<_Up>>
+    { };
+
   /// is_nothrow_default_constructible
   template<typename _Tp>
     struct is_nothrow_default_constructible
@@ -1496,7 +1506,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
   template<typename _From, typename _To>
     struct is_convertible
-    : public __bool_constant<__is_convertible(_From, _To)>
+    : public __bool_constant<__is_convertible(__add_rval_ref_t<_From>, _To)>
     { };
 #else
   template<typename _From, typename _To,
@@ -1547,7 +1557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// is_nothrow_convertible_v
   template<typename _From, typename _To>
     inline constexpr bool is_nothrow_convertible_v
-      = __is_nothrow_convertible(_From, _To);
+      = __is_nothrow_convertible(__add_rval_ref_t<_From>, _To);

   /// is_nothrow_convertible
   template<typename _From, typename _To>



I think this should be OK but I haven't tested it yet.

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

* [Bug libstdc++/100667] [11/12/13/14 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (11 preceding siblings ...)
  2024-03-27 17:44 ` redi at gcc dot gnu.org
@ 2024-03-28 18:26 ` cvs-commit at gcc dot gnu.org
  2024-03-28 22:33 ` [Bug libstdc++/100667] [11/12/13 " redi at gcc dot gnu.org
  2024-05-01 20:31 ` cvs-commit at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-28 18:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:8bb3ef3f6e335e8794590fb712a2661d11d21973

commit r14-9713-g8bb3ef3f6e335e8794590fb712a2661d11d21973
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 27 16:14:01 2024 -0400

    c++: __is_constructible ref binding [PR100667]

    The requirement that a type argument be complete is excessive in the case
of
    direct reference binding to the same type, which does not rely on any
    properties of the type.  This is LWG 2939.

            PR c++/100667

    gcc/cp/ChangeLog:

            * semantics.cc (same_type_ref_bind_p): New.
            (finish_trait_expr): Use it.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/is_constructible8.C: New test.

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

* [Bug libstdc++/100667] [11/12/13 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (12 preceding siblings ...)
  2024-03-28 18:26 ` cvs-commit at gcc dot gnu.org
@ 2024-03-28 22:33 ` redi at gcc dot gnu.org
  2024-05-01 20:31 ` cvs-commit at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-28 22:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |std::tuple<A&&> cannot be   |std::tuple<A&&> cannot be
                   |constructed from A&&, if A  |constructed from A&&, if A
                   |not defined (only forward   |not defined (only forward
                   |declared)                   |declared)

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk now, thanks, Jason.

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

* [Bug libstdc++/100667] [11/12/13 Regression] std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared)
  2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
                   ` (13 preceding siblings ...)
  2024-03-28 22:33 ` [Bug libstdc++/100667] [11/12/13 " redi at gcc dot gnu.org
@ 2024-05-01 20:31 ` cvs-commit at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-01 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:19821ce86afa0f4ce0d2312b16864c809e605be9

commit r13-8667-g19821ce86afa0f4ce0d2312b16864c809e605be9
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 27 16:14:01 2024 -0400

    c++: __is_constructible ref binding [PR100667]

    The requirement that a type argument be complete is excessive in the case
of
    direct reference binding to the same type, which does not rely on any
    properties of the type.  This is LWG 2939.

            PR c++/100667

    gcc/cp/ChangeLog:

            * semantics.cc (same_type_ref_bind_p): New.
            (finish_trait_expr): Use it.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/is_constructible8.C: New test.

    (cherry picked from commit 8bb3ef3f6e335e8794590fb712a2661d11d21973)

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

end of thread, other threads:[~2024-05-01 20:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19  8:00 [Bug libstdc++/100667] New: std::tuple<A&&> cannot be constructed from A&&, if A not defined (only forward declared) piotrwn1 at gmail dot com
2021-05-19  9:09 ` [Bug libstdc++/100667] [11/12 Regression] " redi at gcc dot gnu.org
2021-06-18  7:56 ` ostash at ostash dot kiev.ua
2021-07-28  7:07 ` rguenth at gcc dot gnu.org
2022-04-21  7:49 ` rguenth at gcc dot gnu.org
2023-05-29 10:05 ` [Bug libstdc++/100667] [11/12/13/14 " jakub at gcc dot gnu.org
2023-05-29 11:16 ` piotrwn1 at gmail dot com
2024-03-27 12:59 ` redi at gcc dot gnu.org
2024-03-27 13:36 ` redi at gcc dot gnu.org
2024-03-27 14:02 ` redi at gcc dot gnu.org
2024-03-27 14:03 ` redi at gcc dot gnu.org
2024-03-27 14:14 ` redi at gcc dot gnu.org
2024-03-27 17:44 ` redi at gcc dot gnu.org
2024-03-28 18:26 ` cvs-commit at gcc dot gnu.org
2024-03-28 22:33 ` [Bug libstdc++/100667] [11/12/13 " redi at gcc dot gnu.org
2024-05-01 20:31 ` 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).