diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-08-15 00:15:12 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-08-15 00:15:12 +0000 |
commit | 56b5d3b48bce83cd429befde35933f5105df21e2 (patch) | |
tree | 00fc9c8d2a7b382b142a966c9bce9fcdbaef0e0f /libstdc++-v3 | |
parent | 715a572a8a19d90b8dc02601adbae32a1a78652d (diff) | |
download | gcc-56b5d3b48bce83cd429befde35933f5105df21e2.zip gcc-56b5d3b48bce83cd429befde35933f5105df21e2.tar.gz gcc-56b5d3b48bce83cd429befde35933f5105df21e2.tar.bz2 |
re PR libstdc++/58163 ([C++11] Pedantic assert on str[str.size()] is wrong in C++11)
2013-08-14 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/58163
* include/bits/basic_string.h (basic_string<>::operator[]): Fix
_GLIBCXX_DEBUG_PEDASSERT check vs C++11.
* include/ext/vstring.h: Likewise.
* testsuite/21_strings/basic_string/element_access/char/58163.cc:
New.
* testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc:
Likewise.
* testsuite/ext/vstring/element_access/char/58163.cc: Likewise.
* testsuite/ext/vstring/element_access/wchar_t/58163.cc: Likewise.
From-SVN: r201755
Diffstat (limited to 'libstdc++-v3')
7 files changed, 180 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 719763e..8fea147 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2013-08-14 Paolo Carlini <paolo.carlini@oracle.com> + + PR libstdc++/58163 + * include/bits/basic_string.h (basic_string<>::operator[]): Fix + _GLIBCXX_DEBUG_PEDASSERT check vs C++11. + * include/ext/vstring.h: Likewise. + * testsuite/21_strings/basic_string/element_access/char/58163.cc: + New. + * testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc: + Likewise. + * testsuite/ext/vstring/element_access/char/58163.cc: Likewise. + * testsuite/ext/vstring/element_access/wchar_t/58163.cc: Likewise. + 2013-08-14 Uros Bizjak <ubizjak@gmail.com> * src/c++98/compatibility.cc (_ZTIe): Use diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index cbea566..c8723ed 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -842,10 +842,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION reference operator[](size_type __pos) { - // allow pos == size() as v3 extension: + // Allow pos == size() both in C++98 mode, as v3 extension, + // and in C++11 mode. _GLIBCXX_DEBUG_ASSERT(__pos <= size()); - // but be strict in pedantic mode: - _GLIBCXX_DEBUG_PEDASSERT(__pos < size()); + // In pedantic mode be strict in C++98 mode. + _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); _M_leak(); return _M_data()[__pos]; } diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 43edb53..8532213 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -557,10 +557,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION reference operator[](size_type __pos) { - // allow pos == size() as v3 extension: + // Allow pos == size() both in C++98 mode, as v3 extension, + // and in C++11 mode. _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); - // but be strict in pedantic mode: - _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size()); + // In pedantic mode be strict in C++98 mode. + _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L + || __pos < this->size()); this->_M_leak(); return this->_M_data()[__pos]; } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/58163.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/58163.cc new file mode 100644 index 0000000..ea42027 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/58163.cc @@ -0,0 +1,39 @@ +// 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/>. + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } + +#include <string> +#include <testsuite_hooks.h> + +// PR c++/58163 +void test01() +{ + bool test __attribute__((unused)) = true; + + const std::string cs; + std::string s; + + VERIFY( cs[0] == '\0' ); + VERIFY( s[0] == '\0' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc new file mode 100644 index 0000000..a523908 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc @@ -0,0 +1,39 @@ +// 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/>. + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } + +#include <string> +#include <testsuite_hooks.h> + +// PR c++/58163 +void test01() +{ + bool test __attribute__((unused)) = true; + + const std::wstring cs; + std::wstring s; + + VERIFY( cs[0] == L'\0' ); + VERIFY( s[0] == L'\0' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/vstring/element_access/char/58163.cc b/libstdc++-v3/testsuite/ext/vstring/element_access/char/58163.cc new file mode 100644 index 0000000..cd58be5 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/vstring/element_access/char/58163.cc @@ -0,0 +1,40 @@ +// 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/>. + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } +// { dg-require-string-conversions "" } + +#include <ext/vstring.h> +#include <testsuite_hooks.h> + +// PR c++/58163 +void test01() +{ + bool test __attribute__((unused)) = true; + + const __gnu_cxx::__vstring cs; + __gnu_cxx::__vstring s; + + VERIFY( cs[0] == '\0' ); + VERIFY( s[0] == '\0' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/vstring/element_access/wchar_t/58163.cc b/libstdc++-v3/testsuite/ext/vstring/element_access/wchar_t/58163.cc new file mode 100644 index 0000000..29ca38e --- /dev/null +++ b/libstdc++-v3/testsuite/ext/vstring/element_access/wchar_t/58163.cc @@ -0,0 +1,40 @@ +// 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/>. + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } +// { dg-require-string-conversions "" } + +#include <ext/vstring.h> +#include <testsuite_hooks.h> + +// PR c++/58163 +void test01() +{ + bool test __attribute__((unused)) = true; + + const __gnu_cxx::__wvstring cs; + __gnu_cxx::__wvstring s; + + VERIFY( cs[0] == L'\0' ); + VERIFY( s[0] == L'\0' ); +} + +int main() +{ + test01(); + return 0; +} |