https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
Bug ID: 94489 Summary: ICE: unexpected expression ‘std::min’ of kind overload Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bisqwit at iki dot fi Target Milestone: --- On GCC 9.3.0: $ g++-9 test5.cc -std=c++2a -g -fconcepts test5.cc: In instantiation of ‘auto Mul(const T&, const T2&) [with T = std::array<float, 2>; T2 = std::array<float, 2>]’: test5.cc:33:62: required from here test5.cc:28:117: internal compiler error: unexpected expression ‘std::min’ of kind overload 28 | return typename arith_result<T,T2>::type { std::plus<void>(std::get<P>(vec), std::get<P>(val)) ... }; | ^ 0x7f78e300ce0a __libc_start_main ../csu/libc-start.c:308 On 10.0.1 20200324 (experimental) [master revision 596c90d3559:023579257f5:906b3eb9df6c577d3f6e9c3ea5c9d7e4d1e90536]: $ g++-10 test5.cc -std=c++20 -g test5.cc: In instantiation of ‘auto Mul(const T&, const T2&) [with T = std::array<float, 2>; T2 = std::array<float, 2>]’: test5.cc:33:62: required from here test5.cc:28:117: internal compiler error: unexpected expression ‘std::min’ of kind overload 28 | return typename arith_result<T,T2>::type { std::plus<void>(std::get<P>(vec), std::get<P>(val)) ... }; | ^ 0x63d82b cxx_eval_constant_expression ../../src/gcc/cp/constexpr.c:6301 0x637ded cxx_eval_call_expression ../../src/gcc/cp/constexpr.c:2055 0x63ad65 cxx_eval_constant_expression ../../src/gcc/cp/constexpr.c:5483 0x63ccc2 cxx_eval_indirect_ref ../../src/gcc/cp/constexpr.c:4213 0x63ccc2 cxx_eval_constant_expression ../../src/gcc/cp/constexpr.c:5704 0x63dbe0 cxx_eval_outermost_constant_expr ../../src/gcc/cp/constexpr.c:6502 0x63e5ec cxx_constant_value(tree_node*, tree_node*) ../../src/gcc/cp/constexpr.c:6659 0x733823 expand_integer_pack ../../src/gcc/cp/pt.c:3751 0x733823 expand_builtin_pack_call ../../src/gcc/cp/pt.c:3790 0x733823 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:12714 0x735561 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:13078 0x73a678 tsubst_argument_pack(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:13040 0x735534 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:13090 0x7356e5 tsubst_aggr_type ../../src/gcc/cp/pt.c:13295 0x72c6f4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.c:20100 0x7304e4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.c:15745 0x7304e4 tsubst(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:15745 0x735466 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:13092 0x7356e5 tsubst_aggr_type ../../src/gcc/cp/pt.c:13295 0x7307fe tsubst(tree_node*, tree_node*, int, tree_node*) ../../src/gcc/cp/pt.c:15633 Code is listed below. #include <array> #include <tuple> #include <functional> template<typename T, std::size_t MinSz = 1, std::size_t MaxSz = ~std::size_t{}> concept IsTuple = requires(T t) { {std::get<0>(t) };} and (std::tuple_size_v<std::remove_cvref_t<T>>-MinSz) <= (MaxSz-MinSz); template<IsTuple T, IsTuple T2, std::size_t dim = std::min(std::tuple_size_v<T>,std::tuple_size_v<T2>), class seq = decltype(std::make_index_sequence<dim>{})> struct arith_result { template<std::size_t... I> static auto t(std::index_sequence<I...>) -> std::tuple<std::common_type_t<std::tuple_element_t<I,T>, std::tuple_element_t<I,T2>>...>; template<std::size_t... I> static auto a(std::index_sequence<I...>) -> std::array<std::common_type_t<std::tuple_element_t<I,T>..., std::tuple_element_t<I,T2>...>, dim>; using type = std::conditional_t<requires(T t){t[0]; }, decltype(a(seq{})), decltype(t(seq{}))>; }; template<typename T = std::array<float,3>, typename T2 = T> auto Mul(const T& vec, const T2& val) { return [&]<std::size_t... P>(std::index_sequence<P...>) { return typename arith_result<T,T2>::type { std::plus<void>(std::get<P>(vec), std::get<P>(val)) ... }; } (std::make_index_sequence<std::min(std::tuple_size_v<std::remove_cvref_t<decltype(vec)>>, std::tuple_size_v<std::remove_cvref_t<decltype(val)>>)>{}); } auto x = Mul(std::array<float,2>{}, std::array<float,2>{});