From 7e66313066525b0ce38e140e6d9c815e19d119bf Mon Sep 17 00:00:00 2001 From: paolo Date: Thu, 15 Aug 2013 00:15:12 +0000 Subject: [PATCH] 2013-08-14 Paolo Carlini 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201755 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 13 +++++++ libstdc++-v3/include/bits/basic_string.h | 7 ++-- libstdc++-v3/include/ext/vstring.h | 8 +++-- .../basic_string/element_access/char/58163.cc | 39 +++++++++++++++++++++ .../basic_string/element_access/wchar_t/58163.cc | 39 +++++++++++++++++++++ .../ext/vstring/element_access/char/58163.cc | 40 ++++++++++++++++++++++ .../ext/vstring/element_access/wchar_t/58163.cc | 40 ++++++++++++++++++++++ 7 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/58163.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc create mode 100644 libstdc++-v3/testsuite/ext/vstring/element_access/char/58163.cc create mode 100644 libstdc++-v3/testsuite/ext/vstring/element_access/wchar_t/58163.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 719763e527c..8fea1475468 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2013-08-14 Paolo Carlini + + 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 * 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 cbea5664e71..c8723ededd9 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 43edb53b41c..85322130cf9 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 00000000000..ea42027960b --- /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 +// . + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } + +#include +#include + +// 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 00000000000..a52390810e3 --- /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 +// . + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } + +#include +#include + +// 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 00000000000..cd58be56378 --- /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 +// . + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } +// { dg-require-string-conversions "" } + +#include +#include + +// 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 00000000000..29ca38eea97 --- /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 +// . + +// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG_PEDANTIC" } +// { dg-require-string-conversions "" } + +#include +#include + +// 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; +} -- 2.11.4.GIT