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

Reply via email to