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

            Bug ID: 94628
           Summary: segfault decltype
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland at rschulz dot eu
  Target Milestone: ---

GCC 9.3 and trunk. Internal compiler error: Segmentation fault

#include <type_traits>
#include <utility>

template<int i>
using int_constant = std::integral_constant<int, i>;

template<int I, int...Is, class F, class...Args>
auto select(int i, F&&f, Args&&...args) -> 
    std::common_type_t<decltype(std::forward<F>(f)(int_constant<I>(), 
std::forward<decltype(args)>(args)...)),
                       decltype(std::forward<F>(f)(int_constant<Is>(),
std::forward<decltype(args)>(args)...))...>
{
    if (i == I) return std::forward<F>(f)(int_constant<I>(),
std::forward<Args>(args)...);
    else {
        if constexpr(sizeof...(Is)>0) 
            return select<Is...>(i, std::forward<F>(f),
std::forward<Args>(args)...);
    }
}

int t(int i) {
    return select<0, 1>(i, [](auto x){ return int(x);});
}


No problem if `decltype(args)` is replaced with `Args`. 

https://godbolt.org/z/kPpEK8

Reply via email to