public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Add static_assert to std::integer_sequence [PR112473]
@ 2023-11-11  0:44 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-11-11  0:44 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/bits/utility.h                       | 3 +++
 libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc

diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h
index 8766dfbc15f..ebcf5ba36b2 100644
--- a/libstdc++-v3/include/bits/utility.h
+++ b/libstdc++-v3/include/bits/utility.h
@@ -166,6 +166,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp, _Tp... _Idx>
     struct integer_sequence
     {
+#if __cplusplus >= 202002L
+      static_assert(is_integral_v<_Tp>);
+#endif
       typedef _Tp value_type;
       static constexpr size_t size() noexcept { return sizeof...(_Idx); }
     };
diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc b/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc
new file mode 100644
index 00000000000..14abfbc8149
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc
@@ -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 }
-- 
2.41.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-11  0:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11  0:44 [committed] libstdc++: Add static_assert to std::integer_sequence [PR112473] Jonathan Wakely

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).