From: Ville Voutilainen Date: Mon, 13 Mar 2017 19:44:42 +0000 (+0200) Subject: re PR libstdc++/80034 (unqualified calls to std::distance in std::list::sort) X-Git-Tag: releases/gcc-5.5.0~474 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=357c5fee98e516c1935247e0cfb929ba777ebc92;p=thirdparty%2Fgcc.git re PR libstdc++/80034 (unqualified calls to std::distance in std::list::sort) PR libstdc++/80034 * include/bits/list.tcc (merge(list&&)): Use const for the size_t in the function and in the catch-block, qualify uses of std::distance. (merge(list&&, _StrictWeakOrdering)): Likewise. * testsuite/23_containers/list/operations/80034.cc: New. From-SVN: r246109 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 87c626e8be45..50af6a14a50e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2017-03-13 Ville Voutilainen + + PR libstdc++/80034 + * include/bits/list.tcc (merge(list&&)): Use const for the size_t + in the function and in the catch-block, qualify uses of std::distance. + (merge(list&&, _StrictWeakOrdering)): Likewise. + * testsuite/23_containers/list/operations/80034.cc: New. + 2017-03-02 Jonathan Wakely PR libstdc++/79789 diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index b812b19d6d4a..1a0bb4891519 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -344,7 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator __last1 = end(); iterator __first2 = __x.begin(); iterator __last2 = __x.end(); - size_t __orig_size = __x.size(); + const size_t __orig_size = __x.size(); __try { while (__first1 != __last1 && __first2 != __last2) if (*__first2 < *__first1) @@ -363,7 +363,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } __catch(...) { - size_t __dist = distance(__first2, __last2); + const size_t __dist = std::distance(__first2, __last2); this->_M_inc_size(__orig_size - __dist); __x._M_set_size(__dist); __throw_exception_again; @@ -391,7 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator __last1 = end(); iterator __first2 = __x.begin(); iterator __last2 = __x.end(); - size_t __orig_size = __x.size(); + const size_t __orig_size = __x.size(); __try { while (__first1 != __last1 && __first2 != __last2) @@ -411,7 +411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } __catch(...) { - size_t __dist = distance(__first2, __last2); + const size_t __dist = std::distance(__first2, __last2); this->_M_inc_size(__orig_size - __dist); __x._M_set_size(__dist); __throw_exception_again; diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/80034.cc b/libstdc++-v3/testsuite/23_containers/list/operations/80034.cc new file mode 100644 index 000000000000..5c3decd9dff9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/80034.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// Copyright (C) 2017 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 +// . + +#include + +namespace X { + struct Y { }; + bool operator<(Y, Y) { return false; } + template + void distance(T, T) { } +} + +int main() +{ + std::list l; + l.sort(); +}