Patchwork [v3] libstdc++/58403

login
register
mail settings
Submitter Paolo Carlini
Date Sept. 12, 2013, 3:16 p.m.
Message ID <5231DAD8.7020800@oracle.com>
Download mbox | patch
Permalink /patch/274566/
State New
Headers show

Comments

Paolo Carlini - Sept. 12, 2013, 3:16 p.m.
Hi,

see the audit trail for details. Tested x86_64-linux, committed to mainline.

Thanks,
Paolo.

////////////////////////
2013-09-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/58403
	* include/bits/stl_iterator.h (__normal_iterator<>::operator[],
	operator+=, operator+, operator-=, operator-): Take the argument
	by value.
	* testsuite/24_iterators/normal_iterator/58403.cc: New.

Patch

Index: include/bits/stl_iterator.h
===================================================================
--- include/bits/stl_iterator.h	(revision 202517)
+++ include/bits/stl_iterator.h	(working copy)
@@ -783,23 +783,23 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       // Random access iterator requirements
       reference
-      operator[](const difference_type& __n) const
+      operator[](difference_type __n) const
       { return _M_current[__n]; }
 
       __normal_iterator&
-      operator+=(const difference_type& __n)
+      operator+=(difference_type __n)
       { _M_current += __n; return *this; }
 
       __normal_iterator
-      operator+(const difference_type& __n) const
+      operator+(difference_type __n) const
       { return __normal_iterator(_M_current + __n); }
 
       __normal_iterator&
-      operator-=(const difference_type& __n)
+      operator-=(difference_type __n)
       { _M_current -= __n; return *this; }
 
       __normal_iterator
-      operator-(const difference_type& __n) const
+      operator-(difference_type __n) const
       { return __normal_iterator(_M_current - __n); }
 
       const _Iterator&
Index: testsuite/24_iterators/normal_iterator/58403.cc
===================================================================
--- testsuite/24_iterators/normal_iterator/58403.cc	(revision 0)
+++ testsuite/24_iterators/normal_iterator/58403.cc	(working copy)
@@ -0,0 +1,34 @@ 
+// { dg-options "-std=gnu++11" }
+// { dg-do link }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string>
+#include <iterator>
+
+struct A {
+  static constexpr std::iterator_traits<
+    std::string::iterator>::difference_type a = 1;
+};
+
+int main()
+{
+  std::string s = "foo";
+  auto it = s.begin();
+  it += A::a;
+}