diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-09-12 15:15:34 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-09-12 15:15:34 +0000 |
commit | 274ddab613ae4f3427eaf02859e5bbcceabbaadf (patch) | |
tree | 5dbcdb2b8de10a78d57844730eb2d48614cd4c14 | |
parent | 7480a018a5aacaee6449cfcc59423c2edb9dc403 (diff) | |
download | gcc-274ddab613ae4f3427eaf02859e5bbcceabbaadf.zip gcc-274ddab613ae4f3427eaf02859e5bbcceabbaadf.tar.gz gcc-274ddab613ae4f3427eaf02859e5bbcceabbaadf.tar.bz2 |
re PR libstdc++/58403 (__normal_iterator triggers odr-use)
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.
From-SVN: r202531
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 10 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/normal_iterator/58403.cc | 34 |
3 files changed, 47 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6eab7c7..159fec6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +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. + 2013-09-11 Mitsuru Kariya <kariya_mitsuru@hotmail.com> Chris Jefferson <chris@bubblescope.net> diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 9952c2c..cde442f 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -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& diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/58403.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/58403.cc new file mode 100644 index 0000000..0c7e281 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/normal_iterator/58403.cc @@ -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; +} |