]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make __max_size_type and __max_diff_type structural
authorPatrick Palka <ppalka@redhat.com>
Tue, 10 Jun 2025 14:15:25 +0000 (10:15 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 10 Jun 2025 14:15:25 +0000 (10:15 -0400)
This patch makes these integer-class types structural types by
public-izing their data members so that they could be used as NTTP
types.  I don't think this is required by the standard, but it seems
like a useful extension.

libstdc++-v3/ChangeLog:

* include/bits/max_size_type.h (__max_size_type::_M_val): Make
public instead of private.
(__max_size_type::_M_msb): Likewise.
(__max_diff_type::_M_rep): Likewise.
* testsuite/std/ranges/iota/max_size_type.cc: Verify
__max_diff_type and __max_size_type are structural.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/max_size_type.h
libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc

index 5bec0b5a519a3b6e9c9b8920a6ba09a1485e368e..e602b1b4bee513ab605baa15887024cb63773ac7 100644 (file)
@@ -425,10 +425,11 @@ namespace ranges
       using __rep = unsigned long long;
 #endif
       static constexpr size_t _S_rep_bits = sizeof(__rep) * __CHAR_BIT__;
-    private:
+
       __rep _M_val = 0;
       unsigned _M_msb:1 = 0;
 
+    private:
       constexpr explicit
       __max_size_type(__rep __val, int __msb) noexcept
        : _M_val(__val), _M_msb(__msb)
@@ -752,7 +753,6 @@ namespace ranges
       { return !(__l < __r); }
 #endif
 
-    private:
       __max_size_type _M_rep = 0;
 
       friend class __max_size_type;
index 3e6f954ceb0c5df8a242ba4d1e7ce8b1e1ba2a40..4739d9e2f7904027964953f320582e5535f3e73b 100644 (file)
@@ -400,6 +400,13 @@ static_assert(max_diff_t(max_size_t(1)
                         << (numeric_limits<max_size_t>::digits-1))
              == numeric_limits<max_diff_t>::min());
 
+// Verify that the types are structural types and can therefore be used
+// as NTTP types.
+template<max_size_t V> struct Su { static_assert(V*V == V+132); };
+template<max_diff_t V> struct Ss { static_assert(V*V == V+132); };
+template struct Su<12>;
+template struct Ss<12>;
+
 int
 main()
 {