public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload
@ 2020-04-05 1:50 bisqwit at iki dot fi
2020-04-06 6:39 ` [Bug c++/94489] " marxin at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: bisqwit at iki dot fi @ 2020-04-05 1:50 UTC (permalink / raw)
To: gcc-bugs
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>{});
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94489] ICE: unexpected expression ‘std::min’ of kind overload
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
@ 2020-04-06 6:39 ` marxin at gcc dot gnu.org
2020-04-06 20:30 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-06 6:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-04-06
CC| |jason at gcc dot gnu.org,
| |marxin at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r9-6542-gf869f40780836d17 with -fconcepts, without it started with
r10-3735-gcb57504a55015891.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94489] ICE: unexpected expression ‘std::min’ of kind overload
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
2020-04-06 6:39 ` [Bug c++/94489] " marxin at gcc dot gnu.org
@ 2020-04-06 20:30 ` mpolacek at gcc dot gnu.org
2020-04-06 23:19 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-06 20:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Keywords|ice-on-valid-code |ice-on-invalid-code,
| |needs-reduction
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Doesn't seem like valid code; clang++ trunk also rejects it:
94489.C:28:61: error: no matching constructor for initialization of
'std::plus<void>'
I think the fix should be
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3748,6 +3748,7 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t
complain,
}
else
{
+ hi = instantiate_non_dependent_expr_sfinae (hi, complain);
hi = cxx_constant_value (hi);
int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1;
but it'd be nice to have a reduced version.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94489] ICE: unexpected expression ‘std::min’ of kind overload
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
2020-04-06 6:39 ` [Bug c++/94489] " marxin at gcc dot gnu.org
2020-04-06 20:30 ` mpolacek at gcc dot gnu.org
@ 2020-04-06 23:19 ` mpolacek at gcc dot gnu.org
2020-04-06 23:50 ` mpolacek at gcc dot gnu.org
2024-02-19 15:44 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-06 23:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Likely still invalid, but it compiles without errors with the patch above.
template <typename, unsigned> struct S { };
template <typename T, unsigned N> using U = S<T, __integer_pack(N)...>;
template <typename T> constexpr long g(T) { return 1l; }
template<typename T, typename TT = U<T, g(T{})>> struct X { };
template<typename T>
auto foo(T)
{
[]<unsigned>() {
foo(1);
X<T> x;
};
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94489] ICE: unexpected expression ‘std::min’ of kind overload
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
` (2 preceding siblings ...)
2020-04-06 23:19 ` mpolacek at gcc dot gnu.org
@ 2020-04-06 23:50 ` mpolacek at gcc dot gnu.org
2024-02-19 15:44 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-06 23:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #2)
> Doesn't seem like valid code; clang++ trunk also rejects it:
> 94489.C:28:61: error: no matching constructor for initialization of
> 'std::plus<void>'
>
> I think the fix should be
>
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -3748,6 +3748,7 @@ expand_integer_pack (tree call, tree args,
> tsubst_flags_t complain,
> }
> else
> {
> + hi = instantiate_non_dependent_expr_sfinae (hi, complain);
> hi = cxx_constant_value (hi);
> int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1;
>
>
> but it'd be nice to have a reduced version.
This is not a complete fix because this one ICEs even with that:
template <typename, int...> struct b;
template <typename T, T... d> using e = b<T, __integer_pack(d)...>;
template <unsigned d> using f = e<unsigned, d>;
template <typename T> constexpr long g(T) { return 1l; }
struct array { };
template <typename> constexpr unsigned h{};
template<typename T, long dim = g(h<T>), class X = decltype(f<dim>{})> struct k
{ int n; };
template<typename T, typename U>
auto m(T t, U)
{
[t] <unsigned> () {
m(array{}, array{});
return k<T, 1>::n;
};
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94489] ICE: unexpected expression ‘std::min’ of kind overload
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
` (3 preceding siblings ...)
2020-04-06 23:50 ` mpolacek at gcc dot gnu.org
@ 2024-02-19 15:44 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-02-19 15:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94489
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
If we change std::plus<void> to std::plus<void>{} in order to make the testcase
valid, then we accept ever since the PR94490 fix.
The comment #4 testcase can be further reduced to:
template<int...> struct A;
template<int... Ns> A<__integer_pack(Ns)...>* f();
int main() {
f<5, 6>();
}
This seems invalid indeed, how should we even expand __integer_pack(Ns)... when
Ns itself is a pack?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-19 15:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-05 1:50 [Bug c++/94489] New: ICE: unexpected expression ‘std::min’ of kind overload bisqwit at iki dot fi
2020-04-06 6:39 ` [Bug c++/94489] " marxin at gcc dot gnu.org
2020-04-06 20:30 ` mpolacek at gcc dot gnu.org
2020-04-06 23:19 ` mpolacek at gcc dot gnu.org
2020-04-06 23:50 ` mpolacek at gcc dot gnu.org
2024-02-19 15:44 ` ppalka 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).