public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-10254] libstdc++: Add static_assert to std::integer_sequence [PR112473]
Date: Mon, 18 Mar 2024 14:06:16 +0000 (GMT)	[thread overview]
Message-ID: <20240318140616.2676A385841F@sourceware.org> (raw)

https://gcc.gnu.org/g:dc0964f43dcee46dcd1843287a541668fd08a4a8

commit r12-10254-gdc0964f43dcee46dcd1843287a541668fd08a4a8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Nov 10 12:21:52 2023 +0000

    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 0953497a81f1e320989b9f2aaa7f56747eddd4a0)

Diff:
---
 libstdc++-v3/include/bits/utility.h                       | 3 +++
 libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h
index 180866e3581..6483a8e537e 100644
--- a/libstdc++-v3/include/bits/utility.h
+++ b/libstdc++-v3/include/bits/utility.h
@@ -163,6 +163,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 }

                 reply	other threads:[~2024-03-18 14:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240318140616.2676A385841F@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).