public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix __gnu_cxx::_Pointer_adapter for long long arithmetic
@ 2018-08-30 12:23 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2018-08-30 12:23 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

	* include/ext/pointer.h (_Pointer_adapter): Define operators for
	pointer arithmetic using long long offsets.
	* testsuite/ext/ext_pointer/1.cc: Test pointer arithmetic using
	long long values.

Tested x86_64-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1739 bytes --]

commit af21edc2b1e8b124b55d2f1a7bd34eeb7fccb889
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 30 12:21:33 2018 +0100

    Fix __gnu_cxx::_Pointer_adapter for long long arithmetic
    
            * include/ext/pointer.h (_Pointer_adapter): Define operators for
            pointer arithmetic using long long offsets.
            * testsuite/ext/ext_pointer/1.cc: Test pointer arithmetic using
            long long values.

diff --git a/libstdc++-v3/include/ext/pointer.h b/libstdc++-v3/include/ext/pointer.h
index ee5c30dfa64..1e89c3779af 100644
--- a/libstdc++-v3/include/ext/pointer.h
+++ b/libstdc++-v3/include/ext/pointer.h
@@ -441,6 +441,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _CXX_POINTER_ARITH_OPERATOR_SET(unsigned int);
       _CXX_POINTER_ARITH_OPERATOR_SET(long);
       _CXX_POINTER_ARITH_OPERATOR_SET(unsigned long);
+#ifdef _GLIBCXX_USE_LONG_LONG
+      _CXX_POINTER_ARITH_OPERATOR_SET(long long);
+      _CXX_POINTER_ARITH_OPERATOR_SET(unsigned long long);
+#endif
 
       // Mathematical Manipulators
       inline _Pointer_adapter& 
diff --git a/libstdc++-v3/testsuite/ext/ext_pointer/1.cc b/libstdc++-v3/testsuite/ext/ext_pointer/1.cc
index 351a9775ec8..bbedc43b12e 100644
--- a/libstdc++-v3/testsuite/ext/ext_pointer/1.cc
+++ b/libstdc++-v3/testsuite/ext/ext_pointer/1.cc
@@ -180,11 +180,25 @@ void test04() {
   VERIFY(bPtr3 == aPtr);
 }
 
+// Check that long long values can be used for pointer arithmetic.
+void test05()
+{
+  A a[2] = { 1, 2 };
+  A_pointer p = a;
+  A_pointer q = p + 0ull;
+  VERIFY( p == q );
+  q += 0ll;
+  VERIFY( p == q );
+  q += 1ll;
+  VERIFY( q->i == p[1ll].i );
+}
+
 int main()
 {
   test01();
   test02();
   test03();
   test04();
+  test05();
   return 0;
 }

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

only message in thread, other threads:[~2018-08-30 12:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-30 12:23 [PATCH] Fix __gnu_cxx::_Pointer_adapter for long long arithmetic 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).