summaryrefslogtreecommitdiff
path: root/absl/strings
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/string_view.h12
-rw-r--r--absl/strings/string_view_test.cc5
2 files changed, 9 insertions, 8 deletions
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index b314bc34..8e348fcd 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -283,7 +283,7 @@ class string_view {
// Returns the ith element of the `string_view` using the array operator.
// Note that this operator does not perform any bounds checking.
constexpr const_reference operator[](size_type i) const {
- return ABSL_ASSERT(i < size()), ptr_[i];
+ return ABSL_HARDENING_ASSERT(i < size()), ptr_[i];
}
// string_view::at()
@@ -303,14 +303,14 @@ class string_view {
//
// Returns the first element of a `string_view`.
constexpr const_reference front() const {
- return ABSL_ASSERT(!empty()), ptr_[0];
+ return ABSL_HARDENING_ASSERT(!empty()), ptr_[0];
}
// string_view::back()
//
// Returns the last element of a `string_view`.
constexpr const_reference back() const {
- return ABSL_ASSERT(!empty()), ptr_[size() - 1];
+ return ABSL_HARDENING_ASSERT(!empty()), ptr_[size() - 1];
}
// string_view::data()
@@ -329,7 +329,7 @@ class string_view {
// Removes the first `n` characters from the `string_view`. Note that the
// underlying string is not changed, only the view.
void remove_prefix(size_type n) {
- assert(n <= length_);
+ ABSL_HARDENING_ASSERT(n <= length_);
ptr_ += n;
length_ -= n;
}
@@ -339,7 +339,7 @@ class string_view {
// Removes the last `n` characters from the `string_view`. Note that the
// underlying string is not changed, only the view.
void remove_suffix(size_type n) {
- assert(n <= length_);
+ ABSL_HARDENING_ASSERT(n <= length_);
length_ -= n;
}
@@ -520,7 +520,7 @@ class string_view {
(std::numeric_limits<difference_type>::max)();
static constexpr size_type CheckLengthInternal(size_type len) {
- return (void)ABSL_ASSERT(len <= kMaxSize), len;
+ return ABSL_HARDENING_ASSERT(len <= kMaxSize), len;
}
static constexpr size_type StrlenInternal(const char* str) {
diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc
index 6ba06144..ff31b51e 100644
--- a/absl/strings/string_view_test.cc
+++ b/absl/strings/string_view_test.cc
@@ -28,6 +28,7 @@
#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/dynamic_annotations.h"
+#include "absl/base/options.h"
#if defined(ABSL_HAVE_STD_STRING_VIEW) || defined(__ANDROID__)
// We don't control the death messaging when using std::string_view.
@@ -820,7 +821,7 @@ TEST(StringViewTest, FrontBackSingleChar) {
TEST(StringViewTest, FrontBackEmpty) {
#ifndef ABSL_USES_STD_STRING_VIEW
-#ifndef NDEBUG
+#if !defined(NDEBUG) || ABSL_OPTION_HARDENED
// Abseil's string_view implementation has debug assertions that check that
// front() and back() are not called on an empty string_view.
absl::string_view sv;
@@ -1130,7 +1131,7 @@ TEST(StringViewTest, Noexcept) {
TEST(StringViewTest, BoundsCheck) {
#ifndef ABSL_USES_STD_STRING_VIEW
-#ifndef NDEBUG
+#if !defined(NDEBUG) || ABSL_OPTION_HARDENED
// Abseil's string_view implementation has bounds-checking in debug mode.
absl::string_view h = "hello";
ABSL_EXPECT_DEATH_IF_SUPPORTED(h[5], "");