public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97938] New: g++ crash when inferring type of auto parameter pack in lambda capture
@ 2020-11-22 20:25 elel at 3wh dot net
  2020-11-23  2:22 ` [Bug c++/97938] " mpolacek at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: elel at 3wh dot net @ 2020-11-22 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97938
           Summary: g++ crash when inferring type of auto parameter pack
                    in lambda capture
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: elel at 3wh dot net
  Target Milestone: ---

The following test case:

#include <iostream>
#include <tuple>

template <typename... Args>
int print_args(Args&&... args) {
  std::cout << (args << ...);
  return sizeof...(args);
}

template <typename T1, typename T2>
auto fwd(const T1& t1, const T2& t2) {
  return std::apply([&t2] (auto&&... ts1) {
    return std::apply([...ts1 = std::forward<decltype(ts1)>(ts1)] (auto&&...
ts2) {
      return print_args(ts1..., std::forward<decltype(ts2)>(ts2)...);
    }, t2);
  }, t1);
}

int main() {
  auto t1 = std::make_tuple(int{1}, float{2});
  auto t2 = std::make_tuple(float{3}, int{4});
  return fwd(t1, t2);
}

Compiled as:
g++ -std=c++20 -g -O2 gcc_crash.cpp

Crashes g++ with the following message:
gcc_crash.cpp: In instantiation of ‘fwd<std::tuple<int, float>,
std::tuple<float, int> >::<lambda(auto:11&& ...)> [with auto:11 = {const int&,
const float&}]’:
/usr/include/c++/10.2.0/type_traits:2506:26:   required by substitution of
‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype
(declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other>
std::__result_of_other_impl::_S_test(int) [with _Fn = fwd<std::tuple<int,
float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>; _Args = {const int&,
const float&}]’
/usr/include/c++/10.2.0/type_traits:2517:55:   required from ‘struct
std::__result_of_impl<false, false, fwd<std::tuple<int, float>,
std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>’
/usr/include/c++/10.2.0/type_traits:138:12:   recursively required by
substitution of ‘template<class _Result, class _Ret> struct
std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename
_CTp::type> > [with _Result = std::__invoke_result<fwd<std::tuple<int, float>,
std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>;
_Ret = void]’
/usr/include/c++/10.2.0/type_traits:138:12:   required from ‘struct
std::__and_<std::__is_invocable_impl<std::__invoke_result<fwd<std::tuple<int,
float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const
float&>, void, true, void>,
std::__call_is_nothrow<std::__invoke_result<fwd<std::tuple<int, float>,
std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>,
fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>,
const int&, const float&> >’
/usr/include/c++/10.2.0/type_traits:2979:12:   required from ‘struct
std::is_nothrow_invocable<fwd<std::tuple<int, float>, std::tuple<float, int>
>::<lambda(auto:11&& ...)>, const int&, const float&>’
/usr/include/c++/10.2.0/tuple:1715:37:   required from ‘constexpr const bool
std::__unpack_std_tuple<template<class _Fn, class ... _ArgTypes> struct
std::is_nothrow_invocable, fwd<std::tuple<int, float>, std::tuple<float, int>
>::<lambda(auto:11&& ...)>, const std::tuple<int, float>&>’
/usr/include/c++/10.2.0/tuple:1730:14:   required from ‘constexpr
decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn = fwd<std::tuple<int,
float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>; _Tuple = const
std::tuple<int, float>&]’
gcc_crash.cpp:12:20:   required from ‘auto fwd(const T1&, const T2&) [with T1 =
std::tuple<int, float>; T2 = std::tuple<float, int>]’
gcc_crash.cpp:22:20:   required from here
gcc_crash.cpp:13:23: internal compiler error: Segmentation fault
   13 |     return std::apply([...ts1 = std::forward<decltype(ts1)>(ts1)]
(auto&&... ts2) {
      |                      
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   14 |       return print_args(ts1..., std::forward<decltype(ts2)>(ts2)...);
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 |     }, t2);
      |     ~                  
Please submit a full bug report,
with preprocessed source if appropriate.

In other scenarios (not the minimal test case above) the same bug triggers the
message:
internal compiler error: in cxx_incomplete_type_diagnostic, at cp/typeck2.c:584

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

end of thread, other threads:[~2022-05-12 12:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-22 20:25 [Bug c++/97938] New: g++ crash when inferring type of auto parameter pack in lambda capture elel at 3wh dot net
2020-11-23  2:22 ` [Bug c++/97938] " mpolacek at gcc dot gnu.org
2020-11-23  2:23 ` [Bug c++/97938] 9/10/11 Regression] " mpolacek at gcc dot gnu.org
2020-11-23  7:36 ` [Bug c++/97938] [9/10/11 " rguenth at gcc dot gnu.org
2021-04-01 22:39 ` jason at gcc dot gnu.org
2021-04-01 22:52 ` jason at gcc dot gnu.org
2021-04-02 16:47 ` cvs-commit at gcc dot gnu.org
2021-04-02 17:03 ` [Bug c++/97938] [9/10 " jason at gcc dot gnu.org
2021-05-20 21:34 ` cvs-commit at gcc dot gnu.org
2021-05-21 14:51 ` cvs-commit at gcc dot gnu.org
2021-05-21 15:19 ` jason at gcc dot gnu.org
2021-05-24  8:33 ` cvs-commit at gcc dot gnu.org
2022-05-12 12:47 ` jason 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).