mirror of git://gcc.gnu.org/git/gcc.git
libstdc++: Add static_assert to std::integer_sequence [PR112473]
C++20 allows class types as non-type template parameters, but
std::integer_sequence explicitly disallows them. Enforce that.
libstdc++-v3/ChangeLog:
PR libstdc++/112473
* include/bits/utility.h (integer_sequence): Add static_assert.
* testsuite/20_util/integer_sequence/112473.cc: New test.
(cherry picked from commit 0953497a81
)
This commit is contained in:
parent
d40796e381
commit
f6ed5e0715
|
@ -163,6 +163,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
template<typename _Tp, _Tp... _Idx>
|
template<typename _Tp, _Tp... _Idx>
|
||||||
struct integer_sequence
|
struct integer_sequence
|
||||||
{
|
{
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
static_assert(is_integral_v<_Tp>);
|
||||||
|
#endif
|
||||||
typedef _Tp value_type;
|
typedef _Tp value_type;
|
||||||
static constexpr size_t size() noexcept { return sizeof...(_Idx); }
|
static constexpr size_t size() noexcept { return sizeof...(_Idx); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// { dg-do compile { target c++20 } }
|
||||||
|
|
||||||
|
// PR libstdc++/112473 - integer_sequence accepts non-integer types
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
std::integer_sequence<std::pair<int, int>, std::pair<int, int>{0, 0}> ic;
|
||||||
|
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
|
Loading…
Reference in New Issue