aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-24 20:12:05 +0000
committerfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-24 20:12:05 +0000
commitffff0e9578ae4eadc569ecffaa212e72377fda34 (patch)
tree4cc414e8a8978598d5aaca734f652967c806288c
parentfa4f365b8559743b59ae52801d74b7dbd4da4fce (diff)
2015-06-24 François Dumont <fdumont@gcc.gnu.org>
* include/bits/basic_string.h (basic_string<>::front()): Add !empty debug check. (basic_string<>::back()): Likewise. (basic_string<>::pop_back()): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@224919 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/bits/basic_string.h51
2 files changed, 48 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1880614ffff..47777ac7c49 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2015-06-24 François Dumont <fdumont@gcc.gnu.org>
+
+ * include/bits/basic_string.h (basic_string<>::front()): Add !empty
+ debug check.
+ (basic_string<>::back()): Likewise.
+ (basic_string<>::pop_back()): Likewise.
+
2015-06-24 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 093f5021de7..923fb83937c 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -39,6 +39,7 @@
#include <ext/atomicity.h>
#include <ext/alloc_traits.h>
#include <debug/debug.h>
+
#if __cplusplus >= 201103L
#include <initializer_list>
#endif
@@ -903,7 +904,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
reference
front() noexcept
- { return operator[](0); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](0);
+ }
/**
* Returns a read-only (constant) reference to the data at the first
@@ -911,7 +915,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
const_reference
front() const noexcept
- { return operator[](0); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](0);
+ }
/**
* Returns a read/write reference to the data at the last
@@ -919,7 +926,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
reference
back() noexcept
- { return operator[](this->size() - 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](this->size() - 1);
+ }
/**
* Returns a read-only (constant) reference to the data at the
@@ -927,7 +937,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
const_reference
back() const noexcept
- { return operator[](this->size() - 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](this->size() - 1);
+ }
#endif
// Modifiers:
@@ -1506,7 +1519,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*/
void
pop_back() noexcept
- { _M_erase(size()-1, 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ _M_erase(size() - 1, 1);
+ }
#endif // C++11
/**
@@ -3308,7 +3324,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
reference
front()
- { return operator[](0); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](0);
+ }
/**
* Returns a read-only (constant) reference to the data at the first
@@ -3316,7 +3335,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
const_reference
front() const _GLIBCXX_NOEXCEPT
- { return operator[](0); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](0);
+ }
/**
* Returns a read/write reference to the data at the last
@@ -3324,7 +3346,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
reference
back()
- { return operator[](this->size() - 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](this->size() - 1);
+ }
/**
* Returns a read-only (constant) reference to the data at the
@@ -3332,7 +3357,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
const_reference
back() const _GLIBCXX_NOEXCEPT
- { return operator[](this->size() - 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ return operator[](this->size() - 1);
+ }
#endif
// Modifiers:
@@ -3819,7 +3847,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
*/
void
pop_back() // FIXME C++11: should be noexcept.
- { erase(size()-1, 1); }
+ {
+ _GLIBCXX_DEBUG_ASSERT(!empty());
+ erase(size() - 1, 1);
+ }
#endif // C++11
/**