+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
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];
}
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];
}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}