public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97601] New: ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array
@ 2020-10-27 18:54 milasudril at gmail dot com
2020-11-19 20:21 ` [Bug c++/97601] " mpolacek at gcc dot gnu.org
2021-08-12 20:25 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: milasudril at gmail dot com @ 2020-10-27 18:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97601
Bug ID: 97601
Summary: ICE when using type determined by
std::tuple_element_t<...>, on tuple generated from
type id stored in std::array
Product: gcc
Version: 10.2.1
URL: https://gcc.godbolt.org/z/n13PKr
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: milasudril at gmail dot com
Target Milestone: ---
Host: any
Target: any
Code that triggers the bug(s). It uses enum values stored in an std::array, to
generate an std::tuple. Using std::tuple_element_t on the generated tuple
causes ICE.
Compiler options: -Wall -std=c++20 -O3
#include <memory>
#include <type_traits>
#include <array>
#include <complex>
namespace Enum
{
template<class T>
using Empty = std::type_identity<T>;
template<class T>
constexpr auto add(T base, std::underlying_type_t<T> offset = 1)
{
return static_cast<T>(std::underlying_type_t<T>(base) +
offset);
}
namespace detail
{
template<auto types,
template<auto>
class EnumItemTraits,
class T = std::make_integer_sequence<size_t,
types.size()>>
struct make_tuple_from_array;
template<auto types, template<auto> class EnumItemTraits,
size_t index>
struct int_to_type_array: public EnumItemTraits<types[index]>
{
};
template<auto types, template<auto> class EnumItemTraits,
size_t... indices>
struct make_tuple_from_array<types,
EnumItemTraits,
std::integer_sequence<size_t,
indices...>>
{
using type =
std::tuple<typename int_to_type_array<types,
EnumItemTraits, indices>::type...>;
};
}
template<auto types, template<auto> class EnumItemTraits>
using TupleFromTypeArray = typename
detail::make_tuple_from_array<types, EnumItemTraits>::type;
}
enum class PortType : size_t
{
RgbaPixels,
GrayscaleRealPixels,
GrayscaleComplexPixels,
};
constexpr PortType begin(Enum::Empty<PortType>) { return PortType::RgbaPixels;
}
constexpr PortType end(Enum::Empty<PortType>)
{
return Enum::add(PortType::GrayscaleComplexPixels);
}
using vec4_t __attribute__((vector_size(16))) = float;
using RgbaValue = vec4_t;
using RealValue = double;
using ComplexValue = std::complex<RealValue>;
template<PortType id>
struct PortTypeToType;
template<>
struct PortTypeToType<PortType::RgbaPixels>
{
using type = std::unique_ptr<RgbaValue[]>;
};
template<>
struct PortTypeToType<PortType::GrayscaleRealPixels>
{
using type = std::unique_ptr<RealValue[]>;
};
template<>
struct PortTypeToType<PortType::GrayscaleComplexPixels>
{
using type = std::unique_ptr<ComplexValue[]>;
};
template<class T>
struct InputPortType
{
using type = std::conditional_t<(sizeof(T) <= 16), T,
std::reference_wrapper<T const>>;
};
template<class T>
struct InputPortType<std::unique_ptr<T[]>>
{
using type = T const*;
};
template<class T>
struct InputPortType<std::unique_ptr<T>>
{
using type = std::reference_wrapper<T const>;
};
namespace detail
{
template<PortType t>
struct GenInputPortType
{
using type = typename InputPortType<typename
PortTypeToType<t>::type>::type;
};
}
namespace detail
{
template<class Object, class F, size_t... I>
constexpr decltype(auto) create_impl(F&& f, std::index_sequence<I...>)
{
return Object{f(std::integral_constant<size_t, I>{})...};
}
}
template<class Tuple, class F, size_t... I>
constexpr decltype(auto) createTuple(F&& f)
{
return detail::create_impl<Tuple>(std::forward<F>(f),
std::make_index_sequence<std::tuple_size_v<Tuple>>{});
}
template<class T>
void doStuffWithTArg(T);
template<class T>
void doStuffWithT();
template<auto types>
class InArgTuple
{
using storage_type = Enum::TupleFromTypeArray<types,
detail::GenInputPortType>;
public:
constexpr explicit InArgTuple()
: m_data{createTuple<storage_type>([]<class Tag>(Tag) {
using T = typename
detail::GenInputPortType<types[Tag::value]>::type;
// Trunk gets stuck here
// internal compiler error: in cxx_eval_constant_expression, at
cp/constexpr.c:6188
using OtherT = std::tuple_element_t<Tag::value, storage_type>;
static_assert(std::is_same_v<T, OtherT>);
T foo{};
// This triggers ICE: in finish_expr_stmt, at cp/semantics.c:681
// doStuffWithT<OtherT>();
doStuffWithT<T>(); // Not ICE
OtherT bar{};
// This also triggers ICE: in tsubst_copy, at cp/pt.c:16485
//doStuffWithTArg(bar);
doStuffWithTArg(foo); // Not ICE
//
// Also in tsubst_copy, at cp/pt.c:16485
//
// return bar;
//
return foo;
})}
{
}
static constexpr auto size() { return types.size(); }
template<size_t index>
constexpr auto get() const
{
static_assert(index < types.size());
return std::get<index>(m_data);
}
private:
storage_type m_data;
};
void test()
{
constexpr std::array<PortType, 1> types{PortType::RgbaPixels};
InArgTuple<types> test{};
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/97601] ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array
2020-10-27 18:54 [Bug c++/97601] New: ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array milasudril at gmail dot com
@ 2020-11-19 20:21 ` mpolacek at gcc dot gnu.org
2021-08-12 20:25 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-11-19 20:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97601
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=87765
Ever confirmed|0 |1
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2020-11-19
Status|UNCONFIRMED |NEW
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Reduced:
typedef int a;
template <typename> struct al;
template <typename b, b am> using an = al<b, __integer_pack(am)...>;
struct {
void ap();
} ar;
template <auto ar, template <auto> class, class = an<a, ar.ap>> struct as;
template <auto ar, template <auto> class at> using au = as<ar, at>;
enum av {};
template <av> struct aw;
template <auto ar> class ax { using ay = au<ar, aw>; };
ax<ar> az;
The ICE is in the same spot as in bug 87765.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/97601] ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array
2020-10-27 18:54 [Bug c++/97601] New: ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array milasudril at gmail dot com
2020-11-19 20:21 ` [Bug c++/97601] " mpolacek at gcc dot gnu.org
@ 2021-08-12 20:25 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12 20:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97601
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2020-11-19 00:00:00 |2021-8-12
URL|https://gcc.godbolt.org/z/n |
|13PKr |
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://gcc.godbolt.org/z/n13PKr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-12 20:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 18:54 [Bug c++/97601] New: ICE when using type determined by std::tuple_element_t<...>, on tuple generated from type id stored in std::array milasudril at gmail dot com
2020-11-19 20:21 ` [Bug c++/97601] " mpolacek at gcc dot gnu.org
2021-08-12 20:25 ` pinskia 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).