re PR libstdc++/58163 ([C++11] Pedantic assert on str[str.size()] is wrong in C++11)
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 15 Aug 2013 00:15:12 +0000 (00:15 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 15 Aug 2013 00:15:12 +0000 (00:15 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/ext/vstring.h
libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/58163.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/58163.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/vstring/element_access/char/58163.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/vstring/element_access/wchar_t/58163.cc [new file with mode: 0644]

index 719763e..8fea147 100644 (file)
@@ -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
index cbea566..c8723ed 100644 (file)
@@ -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];
       }
index 43edb53..8532213 100644 (file)
@@ -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 (file)
index 0000000..ea42027
--- /dev/null
@@ -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 (file)
index 0000000..a523908
--- /dev/null
@@ -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 (file)
index 0000000..cd58be5
--- /dev/null
@@ -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 (file)
index 0000000..29ca38e
--- /dev/null
@@ -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;
+}