Use C++17 [[nodiscard]] instead of the deprecated ABSL_MUST_USE_RESULT

In this change, //absl/status is intentionally excluded because of
complication with SWIG compatibility. This may be handled separately.

PiperOrigin-RevId: 731387819
Change-Id: I71bf2e02f3a477d65575d467f5e5ab163846d31e
This commit is contained in:
Derek Mauro
2025-02-26 11:15:44 -08:00
committed by Copybara-Service
parent 8e1f92a30d
commit 1af129f1c3
26 changed files with 134 additions and 150 deletions

View File

@@ -89,8 +89,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED SpinLock {
// acquisition was successful. If the lock was not acquired, false is
// returned. If this SpinLock is free at the time of the call, TryLock
// will return true with high probability.
ABSL_MUST_USE_RESULT inline bool TryLock()
ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
[[nodiscard]] inline bool TryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_try_lock);
bool res = TryLockImpl();
ABSL_TSAN_MUTEX_POST_LOCK(
@@ -121,7 +120,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED SpinLock {
// Determine if the lock is held. When the lock is held by the invoking
// thread, true will always be returned. Intended to be used as
// CHECK(lock.IsHeld()).
ABSL_MUST_USE_RESULT inline bool IsHeld() const {
[[nodiscard]] inline bool IsHeld() const {
return (lockword_.load(std::memory_order_relaxed) & kSpinLockHeld) != 0;
}
@@ -203,16 +202,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED SpinLock {
// Corresponding locker object that arranges to acquire a spinlock for
// the duration of a C++ scope.
//
// TODO(b/176172494): Use only [[nodiscard]] when baseline is raised.
// TODO(b/6695610): Remove forward declaration when #ifdef is no longer needed.
#if ABSL_HAVE_CPP_ATTRIBUTE(nodiscard)
class [[nodiscard]] SpinLockHolder;
#else
class ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_TRIVIAL_ABI SpinLockHolder;
#endif
class ABSL_SCOPED_LOCKABLE SpinLockHolder {
class ABSL_SCOPED_LOCKABLE [[nodiscard]] SpinLockHolder {
public:
inline explicit SpinLockHolder(SpinLock* l) ABSL_EXCLUSIVE_LOCK_FUNCTION(l)
: lock_(l) {

View File

@@ -78,7 +78,7 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
template <typename Arg, typename Callback = void()>
class ABSL_MUST_USE_RESULT Cleanup final {
class [[nodiscard]] Cleanup final {
static_assert(cleanup_internal::WasDeduced<Arg>(),
"Explicit template parameters are not supported.");

View File

@@ -229,7 +229,7 @@ class AllocationTransaction {
return result.data;
}
ABSL_MUST_USE_RESULT Allocation<A> Release() && {
[[nodiscard]] Allocation<A> Release() && {
Allocation<A> result = {GetData(), GetCapacity()};
Reset();
return result;

View File

@@ -84,7 +84,7 @@ class RustSymbolParser {
// structure was not recognized or exceeded implementation limits, such as by
// nesting structures too deep. In either case *this should not be used
// again.
ABSL_MUST_USE_RESULT bool Parse() && {
[[nodiscard]] bool Parse() && {
// Recursively parses the grammar production named by callee, then resumes
// execution at the next statement.
//
@@ -564,7 +564,7 @@ class RustSymbolParser {
// If the next input character is the given character, consumes it and returns
// true; otherwise returns false without consuming a character.
ABSL_MUST_USE_RESULT bool Eat(char want) {
[[nodiscard]] bool Eat(char want) {
if (encoding_[pos_] != want) return false;
++pos_;
return true;
@@ -573,7 +573,7 @@ class RustSymbolParser {
// Provided there is enough remaining output space, appends c to the output,
// writing a fresh NUL terminator afterward, and returns true. Returns false
// if the output buffer had less than two bytes free.
ABSL_MUST_USE_RESULT bool EmitChar(char c) {
[[nodiscard]] bool EmitChar(char c) {
if (silence_depth_ > 0) return true;
if (out_end_ - out_ < 2) return false;
*out_++ = c;
@@ -584,7 +584,7 @@ class RustSymbolParser {
// Provided there is enough remaining output space, appends the C string token
// to the output, followed by a NUL character, and returns true. Returns
// false if not everything fit into the output buffer.
ABSL_MUST_USE_RESULT bool Emit(const char* token) {
[[nodiscard]] bool Emit(const char* token) {
if (silence_depth_ > 0) return true;
const size_t token_length = std::strlen(token);
const size_t bytes_to_copy = token_length + 1; // token and final NUL
@@ -598,7 +598,7 @@ class RustSymbolParser {
// of disambiguator (if it's nonnegative) or "?" (if it's negative) to the
// output, followed by a NUL character, and returns true. Returns false if
// not everything fit into the output buffer.
ABSL_MUST_USE_RESULT bool EmitDisambiguator(int disambiguator) {
[[nodiscard]] bool EmitDisambiguator(int disambiguator) {
if (disambiguator < 0) return EmitChar('?'); // parsed but too large
if (disambiguator == 0) return EmitChar('0');
// Convert disambiguator to decimal text. Three digits per byte is enough
@@ -618,7 +618,7 @@ class RustSymbolParser {
// On success returns true and fills value with the encoded value if it was
// not too big, otherwise with -1. If the optional disambiguator was omitted,
// value is 0. On parse failure returns false and sets value to -1.
ABSL_MUST_USE_RESULT bool ParseDisambiguator(int& value) {
[[nodiscard]] bool ParseDisambiguator(int& value) {
value = -1;
// disambiguator = s base-62-number
@@ -639,7 +639,7 @@ class RustSymbolParser {
// On success returns true and fills value with the encoded value if it was
// not too big, otherwise with -1. On parse failure returns false and sets
// value to -1.
ABSL_MUST_USE_RESULT bool ParseBase62Number(int& value) {
[[nodiscard]] bool ParseBase62Number(int& value) {
value = -1;
// base-62-number = (digit | lower | upper)* _
@@ -686,7 +686,7 @@ class RustSymbolParser {
// A nonzero uppercase_namespace specifies the character after the N in a
// nested-identifier, e.g., 'C' for a closure, allowing ParseIdentifier to
// write out the name with the conventional decoration for that namespace.
ABSL_MUST_USE_RESULT bool ParseIdentifier(char uppercase_namespace = '\0') {
[[nodiscard]] bool ParseIdentifier(char uppercase_namespace = '\0') {
// identifier -> disambiguator? undisambiguated-identifier
int disambiguator = 0;
if (!ParseDisambiguator(disambiguator)) return false;
@@ -703,7 +703,7 @@ class RustSymbolParser {
//
// At other appearances of undisambiguated-identifier in the grammar, this
// treatment is not applicable, and the call site omits both arguments.
ABSL_MUST_USE_RESULT bool ParseUndisambiguatedIdentifier(
[[nodiscard]] bool ParseUndisambiguatedIdentifier(
char uppercase_namespace = '\0', int disambiguator = 0) {
// undisambiguated-identifier -> u? decimal-number _? bytes
const bool is_punycoded = Eat('u');
@@ -766,7 +766,7 @@ class RustSymbolParser {
// Consumes a decimal number like 0 or 123 from the input. On success returns
// true and fills value with the encoded value. If the encoded value is too
// large or otherwise unparsable, returns false and sets value to -1.
ABSL_MUST_USE_RESULT bool ParseDecimalNumber(int& value) {
[[nodiscard]] bool ParseDecimalNumber(int& value) {
value = -1;
if (!IsDigit(Peek())) return false;
int encoded_number = Take() - '0';
@@ -788,7 +788,7 @@ class RustSymbolParser {
// Consumes a binder of higher-ranked lifetimes if one is present. On success
// returns true and discards the encoded lifetime count. On parse failure
// returns false.
ABSL_MUST_USE_RESULT bool ParseOptionalBinder() {
[[nodiscard]] bool ParseOptionalBinder() {
// binder -> G base-62-number
if (!Eat('G')) return true;
int ignored_binding_count;
@@ -802,7 +802,7 @@ class RustSymbolParser {
// things we omit from output, such as the entire contents of generic-args.
//
// On parse failure returns false.
ABSL_MUST_USE_RESULT bool ParseOptionalLifetime() {
[[nodiscard]] bool ParseOptionalLifetime() {
// lifetime -> L base-62-number
if (!Eat('L')) return true;
int ignored_de_bruijn_index;
@@ -811,14 +811,14 @@ class RustSymbolParser {
// Consumes a lifetime just like ParseOptionalLifetime, but returns false if
// there is no lifetime here.
ABSL_MUST_USE_RESULT bool ParseRequiredLifetime() {
[[nodiscard]] bool ParseRequiredLifetime() {
if (Peek() != 'L') return false;
return ParseOptionalLifetime();
}
// Pushes ns onto the namespace stack and returns true if the stack is not
// full, else returns false.
ABSL_MUST_USE_RESULT bool PushNamespace(char ns) {
[[nodiscard]] bool PushNamespace(char ns) {
if (namespace_depth_ == kNamespaceStackSize) return false;
namespace_stack_[namespace_depth_++] = ns;
return true;
@@ -830,7 +830,7 @@ class RustSymbolParser {
// Pushes position onto the position stack and returns true if the stack is
// not full, else returns false.
ABSL_MUST_USE_RESULT bool PushPosition(int position) {
[[nodiscard]] bool PushPosition(int position) {
if (position_depth_ == kPositionStackSize) return false;
position_stack_[position_depth_++] = position;
return true;
@@ -845,7 +845,7 @@ class RustSymbolParser {
// beginning of the backref target. Returns true on success. Returns false
// if parsing failed, the stack is exhausted, or the backref target position
// is out of range.
ABSL_MUST_USE_RESULT bool BeginBackref() {
[[nodiscard]] bool BeginBackref() {
// backref = B base-62-number (B already consumed)
//
// Reject backrefs that don't parse, overflow int, or don't point backward.

View File

@@ -94,7 +94,7 @@ using Flag = flags_internal::Flag<T>;
// // FLAGS_firstname is a Flag of type `std::string`
// std::string first_name = absl::GetFlag(FLAGS_firstname);
template <typename T>
ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag) {
[[nodiscard]] T GetFlag(const absl::Flag<T>& flag) {
return flags_internal::FlagImplPeer::InvokeGet<T>(flag);
}

View File

@@ -57,7 +57,7 @@ template <typename T>
using Flag = flags_internal::Flag<T>;
template <typename T>
ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag);
[[nodiscard]] T GetFlag(const absl::Flag<T>& flag);
template <typename T>
void SetFlag(absl::Flag<T>* flag, const T& v);

View File

@@ -141,21 +141,20 @@ ABSL_NAMESPACE_BEGIN
// }
//
template <int&... ExplicitBarrier, typename Container>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(const Container& values);
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
const Container& values);
template <int&... ExplicitBarrier, typename Container, typename Eq>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals);
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
const Container& values, Eq equals);
template <int&..., typename T>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(std::initializer_list<T> values);
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
std::initializer_list<T> values);
template <int&..., typename T, typename Eq>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(std::initializer_list<T> values,
Eq equals);
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
std::initializer_list<T> values, Eq equals);
namespace hash_internal {
@@ -184,8 +183,8 @@ struct ExpandVisitor {
};
template <typename Container, typename Eq>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals) {
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
const Container& values, Eq equals) {
using V = typename Container::value_type;
struct Info {
@@ -343,32 +342,31 @@ struct DefaultEquals {
} // namespace hash_internal
template <int&..., typename Container>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(const Container& values) {
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
const Container& values) {
return hash_internal::VerifyTypeImplementsAbslHashCorrectly(
hash_internal::ContainerAsVector<Container>::Do(values),
hash_internal::DefaultEquals{});
}
template <int&..., typename Container, typename Eq>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals) {
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
const Container& values, Eq equals) {
return hash_internal::VerifyTypeImplementsAbslHashCorrectly(
hash_internal::ContainerAsVector<Container>::Do(values), equals);
}
template <int&..., typename T>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(std::initializer_list<T> values) {
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
std::initializer_list<T> values) {
return hash_internal::VerifyTypeImplementsAbslHashCorrectly(
hash_internal::ContainerAsVector<std::initializer_list<T>>::Do(values),
hash_internal::DefaultEquals{});
}
template <int&..., typename T, typename Eq>
ABSL_MUST_USE_RESULT testing::AssertionResult
VerifyTypeImplementsAbslHashCorrectly(std::initializer_list<T> values,
Eq equals) {
testing::AssertionResult VerifyTypeImplementsAbslHashCorrectly(
std::initializer_list<T> values, Eq equals) {
return hash_internal::VerifyTypeImplementsAbslHashCorrectly(
hash_internal::ContainerAsVector<std::initializer_list<T>>::Do(values),
equals);

View File

@@ -60,8 +60,8 @@ namespace log_internal {
// Helper for `ABSL_DIE_IF_NULL`.
template <typename T>
ABSL_MUST_USE_RESULT T DieIfNull(const char* file, int line,
const char* exprtext, T&& t) {
[[nodiscard]] T DieIfNull(const char* file, int line, const char* exprtext,
T&& t) {
if (ABSL_PREDICT_FALSE(t == nullptr)) {
// Call a non-inline helper function for a small code size improvement.
DieBecauseNull(file, line, exprtext);

View File

@@ -43,7 +43,7 @@ ABSL_NAMESPACE_BEGIN
//
// Returns the value of the Minimum Log Level parameter.
// This function is async-signal-safe.
ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast MinLogLevel();
[[nodiscard]] absl::LogSeverityAtLeast MinLogLevel();
// SetMinLogLevel()
//
@@ -82,7 +82,7 @@ class ScopedMinLogLevel final {
//
// Returns the value of the Stderr Threshold parameter.
// This function is async-signal-safe.
ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast StderrThreshold();
[[nodiscard]] absl::LogSeverityAtLeast StderrThreshold();
// SetStderrThreshold()
//
@@ -118,8 +118,7 @@ class ScopedStderrThreshold final {
//
// Returns true if we should log a backtrace at the specified location.
namespace log_internal {
ABSL_MUST_USE_RESULT bool ShouldLogBacktraceAt(absl::string_view file,
int line);
[[nodiscard]] bool ShouldLogBacktraceAt(absl::string_view file, int line);
} // namespace log_internal
// SetLogBacktraceLocation()
@@ -145,7 +144,7 @@ void ClearLogBacktraceLocation();
//
// Returns the value of the Prepend Log Prefix option.
// This function is async-signal-safe.
ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix();
[[nodiscard]] bool ShouldPrependLogPrefix();
// EnableLogPrefix()
//

View File

@@ -123,8 +123,9 @@ bool EncodeBytesTruncate(uint64_t tag, absl::Span<const char> value,
return true;
}
ABSL_MUST_USE_RESULT absl::Span<char> EncodeMessageStart(
uint64_t tag, uint64_t max_size, absl::Span<char> *buf) {
[[nodiscard]] absl::Span<char> EncodeMessageStart(uint64_t tag,
uint64_t max_size,
absl::Span<char> *buf) {
const uint64_t tag_type = MakeTagType(tag, WireType::kLengthDelimited);
const size_t tag_type_size = VarintSize(tag_type);
max_size = std::min<uint64_t>(max_size, buf->size());

View File

@@ -169,9 +169,9 @@ inline bool EncodeStringTruncate(uint64_t tag, absl::string_view value,
// safe to pass to `EncodeMessageLength` but need not be.
// Used for string, bytes, message, and packed-repeated field type.
// Consumes up to kMaxVarintSize * 2 bytes (20).
ABSL_MUST_USE_RESULT absl::Span<char> EncodeMessageStart(uint64_t tag,
uint64_t max_size,
absl::Span<char> *buf);
[[nodiscard]] absl::Span<char> EncodeMessageStart(uint64_t tag,
uint64_t max_size,
absl::Span<char> *buf);
// Finalizes the length field in `msg` so that it encompasses all data encoded
// since the call to `EncodeMessageStart` which returned `msg`. Does nothing if

View File

@@ -34,7 +34,7 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace log_internal {
class ABSL_MUST_USE_RESULT AsLiteralImpl final {
class [[nodiscard]] AsLiteralImpl final {
public:
explicit AsLiteralImpl(absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND)
: str_(str) {}
@@ -66,7 +66,7 @@ enum class StructuredStringType {
// Structured log data for a string and associated structured proto field,
// both of which must outlive this object.
template <StructuredStringType str_type>
class ABSL_MUST_USE_RESULT AsStructuredStringTypeImpl final {
class [[nodiscard]] AsStructuredStringTypeImpl final {
public:
constexpr AsStructuredStringTypeImpl(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND,
@@ -105,7 +105,7 @@ using AsStructuredNotLiteralImpl =
// Structured log data for a stringifyable type T and associated structured
// proto field, both of which must outlive this object.
template <typename T>
class ABSL_MUST_USE_RESULT AsStructuredValueImpl final {
class [[nodiscard]] AsStructuredValueImpl final {
public:
using ValueFormatter = absl::AnyInvocable<std::string(T) const>;

View File

@@ -63,14 +63,14 @@ using std::rotr;
// Rotating functions
template <class T>
ABSL_MUST_USE_RESULT constexpr
[[nodiscard]] constexpr
typename std::enable_if<std::is_unsigned<T>::value, T>::type
rotl(T x, int s) noexcept {
return numeric_internal::RotateLeft(x, s);
}
template <class T>
ABSL_MUST_USE_RESULT constexpr
[[nodiscard]] constexpr
typename std::enable_if<std::is_unsigned<T>::value, T>::type
rotr(T x, int s) noexcept {
return numeric_internal::RotateRight(x, s);

View File

@@ -71,7 +71,7 @@ constexpr bool IsPowerOf2(unsigned int x) noexcept {
}
template <class T>
ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateRight(
[[nodiscard]] ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateRight(
T x, int s) noexcept {
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
@@ -82,7 +82,7 @@ ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateRight(
}
template <class T>
ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateLeft(
[[nodiscard]] ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateLeft(
T x, int s) noexcept {
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),

View File

@@ -54,7 +54,7 @@ static_assert(kEntropyBlocksNeeded > 0,
// to the C++ Standard "Seed Sequence" concept [rand.req.seedseq].
//
// If values.data() == nullptr, the behavior is undefined.
ABSL_MUST_USE_RESULT
[[nodiscard]]
bool ReadSeedMaterialFromOSEntropy(absl::Span<uint32_t> values);
// Attempts to fill a span of uint32_t-values using variates generated by an
@@ -65,8 +65,8 @@ bool ReadSeedMaterialFromOSEntropy(absl::Span<uint32_t> values);
//
// If urbg == nullptr or values.data() == nullptr, the behavior is undefined.
template <typename URBG>
ABSL_MUST_USE_RESULT bool ReadSeedMaterialFromURBG(
URBG* urbg, absl::Span<uint32_t> values) {
[[nodiscard]] bool ReadSeedMaterialFromURBG(URBG* urbg,
absl::Span<uint32_t> values) {
random_internal::FastUniformBits<uint32_t> distr;
assert(urbg != nullptr && values.data() != nullptr);

View File

@@ -188,7 +188,7 @@ inline char ascii_tolower(unsigned char c) {
void AsciiStrToLower(absl::Nonnull<std::string*> s);
// Creates a lowercase string from a given absl::string_view.
ABSL_MUST_USE_RESULT inline std::string AsciiStrToLower(absl::string_view s) {
[[nodiscard]] inline std::string AsciiStrToLower(absl::string_view s) {
std::string result;
strings_internal::STLStringResizeUninitialized(&result, s.size());
ascii_internal::AsciiStrToLower(&result[0], s.data(), s.size());
@@ -199,7 +199,7 @@ ABSL_MUST_USE_RESULT inline std::string AsciiStrToLower(absl::string_view s) {
//
// (Template is used to lower priority of this overload.)
template <int&... DoNotSpecify>
ABSL_MUST_USE_RESULT inline std::string AsciiStrToLower(std::string&& s) {
[[nodiscard]] inline std::string AsciiStrToLower(std::string&& s) {
std::string result = std::move(s);
absl::AsciiStrToLower(&result);
return result;
@@ -217,7 +217,7 @@ inline char ascii_toupper(unsigned char c) {
void AsciiStrToUpper(absl::Nonnull<std::string*> s);
// Creates an uppercase string from a given absl::string_view.
ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(absl::string_view s) {
[[nodiscard]] inline std::string AsciiStrToUpper(absl::string_view s) {
std::string result;
strings_internal::STLStringResizeUninitialized(&result, s.size());
ascii_internal::AsciiStrToUpper(&result[0], s.data(), s.size());
@@ -228,7 +228,7 @@ ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(absl::string_view s) {
//
// (Template is used to lower priority of this overload.)
template <int&... DoNotSpecify>
ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(std::string&& s) {
[[nodiscard]] inline std::string AsciiStrToUpper(std::string&& s) {
std::string result = std::move(s);
absl::AsciiStrToUpper(&result);
return result;
@@ -236,7 +236,7 @@ ABSL_MUST_USE_RESULT inline std::string AsciiStrToUpper(std::string&& s) {
// Returns absl::string_view with whitespace stripped from the beginning of the
// given string_view.
ABSL_MUST_USE_RESULT inline absl::string_view StripLeadingAsciiWhitespace(
[[nodiscard]] inline absl::string_view StripLeadingAsciiWhitespace(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND) {
auto it = std::find_if_not(str.begin(), str.end(), absl::ascii_isspace);
return str.substr(static_cast<size_t>(it - str.begin()));
@@ -250,7 +250,7 @@ inline void StripLeadingAsciiWhitespace(absl::Nonnull<std::string*> str) {
// Returns absl::string_view with whitespace stripped from the end of the given
// string_view.
ABSL_MUST_USE_RESULT inline absl::string_view StripTrailingAsciiWhitespace(
[[nodiscard]] inline absl::string_view StripTrailingAsciiWhitespace(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND) {
auto it = std::find_if_not(str.rbegin(), str.rend(), absl::ascii_isspace);
return str.substr(0, static_cast<size_t>(str.rend() - it));
@@ -264,7 +264,7 @@ inline void StripTrailingAsciiWhitespace(absl::Nonnull<std::string*> str) {
// Returns absl::string_view with whitespace stripped from both ends of the
// given string_view.
ABSL_MUST_USE_RESULT inline absl::string_view StripAsciiWhitespace(
[[nodiscard]] inline absl::string_view StripAsciiWhitespace(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND) {
return StripTrailingAsciiWhitespace(StripLeadingAsciiWhitespace(str));
}

View File

@@ -163,8 +163,8 @@ bool WebSafeBase64Unescape(absl::string_view src,
// output string. If `hex` does not consist of valid hexadecimal data, this
// function returns false and leaves `bytes` in an unspecified state. Returns
// true on success.
ABSL_MUST_USE_RESULT bool HexStringToBytes(absl::string_view hex,
absl::Nonnull<std::string*> bytes);
[[nodiscard]] bool HexStringToBytes(absl::string_view hex,
absl::Nonnull<std::string*> bytes);
// HexStringToBytes()
//

View File

@@ -62,8 +62,8 @@ ABSL_NAMESPACE_BEGIN
// encountered, this function returns `false`, leaving `out` in an unspecified
// state.
template <typename int_type>
ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str,
absl::Nonnull<int_type*> out);
[[nodiscard]] bool SimpleAtoi(absl::string_view str,
absl::Nonnull<int_type*> out);
// SimpleAtof()
//
@@ -74,8 +74,7 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str,
// allowed formats for `str`, except SimpleAtof() is locale-independent and will
// always use the "C" locale. If any errors are encountered, this function
// returns `false`, leaving `out` in an unspecified state.
ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str,
absl::Nonnull<float*> out);
[[nodiscard]] bool SimpleAtof(absl::string_view str, absl::Nonnull<float*> out);
// SimpleAtod()
//
@@ -86,8 +85,8 @@ ABSL_MUST_USE_RESULT bool SimpleAtof(absl::string_view str,
// allowed formats for `str`, except SimpleAtod is locale-independent and will
// always use the "C" locale. If any errors are encountered, this function
// returns `false`, leaving `out` in an unspecified state.
ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str,
absl::Nonnull<double*> out);
[[nodiscard]] bool SimpleAtod(absl::string_view str,
absl::Nonnull<double*> out);
// SimpleAtob()
//
@@ -97,8 +96,7 @@ ABSL_MUST_USE_RESULT bool SimpleAtod(absl::string_view str,
// are interpreted as boolean `false`: "false", "f", "no", "n", "0". If any
// errors are encountered, this function returns `false`, leaving `out` in an
// unspecified state.
ABSL_MUST_USE_RESULT bool SimpleAtob(absl::string_view str,
absl::Nonnull<bool*> out);
[[nodiscard]] bool SimpleAtob(absl::string_view str, absl::Nonnull<bool*> out);
// SimpleHexAtoi()
//
@@ -111,14 +109,14 @@ ABSL_MUST_USE_RESULT bool SimpleAtob(absl::string_view str,
// by this function. If any errors are encountered, this function returns
// `false`, leaving `out` in an unspecified state.
template <typename int_type>
ABSL_MUST_USE_RESULT bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<int_type*> out);
[[nodiscard]] bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<int_type*> out);
// Overloads of SimpleHexAtoi() for 128 bit integers.
ABSL_MUST_USE_RESULT inline bool SimpleHexAtoi(
absl::string_view str, absl::Nonnull<absl::int128*> out);
ABSL_MUST_USE_RESULT inline bool SimpleHexAtoi(
absl::string_view str, absl::Nonnull<absl::uint128*> out);
[[nodiscard]] inline bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<absl::int128*> out);
[[nodiscard]] inline bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<absl::uint128*> out);
ABSL_NAMESPACE_END
} // namespace absl
@@ -229,9 +227,8 @@ absl::Nonnull<char*> FastIntToBuffer(int_type i, absl::Nonnull<char*> buffer)
// Implementation of SimpleAtoi, generalized to support arbitrary base (used
// with base different from 10 elsewhere in Abseil implementation).
template <typename int_type>
ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s,
absl::Nonnull<int_type*> out,
int base) {
[[nodiscard]] bool safe_strtoi_base(absl::string_view s,
absl::Nonnull<int_type*> out, int base) {
static_assert(sizeof(*out) == 1 || sizeof(*out) == 2 || sizeof(*out) == 4 ||
sizeof(*out) == 8,
"SimpleAtoi works only with 8, 16, 32, or 64-bit integers.");
@@ -313,34 +310,34 @@ inline size_t FastHexToBufferZeroPad16(uint64_t val, absl::Nonnull<char*> out) {
} // namespace numbers_internal
template <typename int_type>
ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str,
absl::Nonnull<int_type*> out) {
[[nodiscard]] bool SimpleAtoi(absl::string_view str,
absl::Nonnull<int_type*> out) {
return numbers_internal::safe_strtoi_base(str, out, 10);
}
ABSL_MUST_USE_RESULT inline bool SimpleAtoi(absl::string_view str,
absl::Nonnull<absl::int128*> out) {
[[nodiscard]] inline bool SimpleAtoi(absl::string_view str,
absl::Nonnull<absl::int128*> out) {
return numbers_internal::safe_strto128_base(str, out, 10);
}
ABSL_MUST_USE_RESULT inline bool SimpleAtoi(absl::string_view str,
absl::Nonnull<absl::uint128*> out) {
[[nodiscard]] inline bool SimpleAtoi(absl::string_view str,
absl::Nonnull<absl::uint128*> out) {
return numbers_internal::safe_strtou128_base(str, out, 10);
}
template <typename int_type>
ABSL_MUST_USE_RESULT bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<int_type*> out) {
[[nodiscard]] bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<int_type*> out) {
return numbers_internal::safe_strtoi_base(str, out, 16);
}
ABSL_MUST_USE_RESULT inline bool SimpleHexAtoi(
absl::string_view str, absl::Nonnull<absl::int128*> out) {
[[nodiscard]] inline bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<absl::int128*> out) {
return numbers_internal::safe_strto128_base(str, out, 16);
}
ABSL_MUST_USE_RESULT inline bool SimpleHexAtoi(
absl::string_view str, absl::Nonnull<absl::uint128*> out) {
[[nodiscard]] inline bool SimpleHexAtoi(absl::string_view str,
absl::Nonnull<absl::uint128*> out) {
return numbers_internal::safe_strtou128_base(str, out, 16);
}

View File

@@ -538,28 +538,28 @@ using EnableIfFastCase = T;
} // namespace strings_internal
ABSL_MUST_USE_RESULT inline std::string StrCat() { return std::string(); }
[[nodiscard]] inline std::string StrCat() { return std::string(); }
template <typename T>
ABSL_MUST_USE_RESULT inline std::string StrCat(
[[nodiscard]] inline std::string StrCat(
strings_internal::EnableIfFastCase<T> a) {
return strings_internal::SingleArgStrCat(a);
}
ABSL_MUST_USE_RESULT inline std::string StrCat(const AlphaNum& a) {
[[nodiscard]] inline std::string StrCat(const AlphaNum& a) {
return std::string(a.data(), a.size());
}
ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b);
ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b,
const AlphaNum& c);
ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b,
const AlphaNum& c, const AlphaNum& d);
[[nodiscard]] std::string StrCat(const AlphaNum& a, const AlphaNum& b);
[[nodiscard]] std::string StrCat(const AlphaNum& a, const AlphaNum& b,
const AlphaNum& c);
[[nodiscard]] std::string StrCat(const AlphaNum& a, const AlphaNum& b,
const AlphaNum& c, const AlphaNum& d);
// Support 5 or more arguments
template <typename... AV>
ABSL_MUST_USE_RESULT inline std::string StrCat(
const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, const AlphaNum& d,
const AlphaNum& e, const AV&... args) {
[[nodiscard]] inline std::string StrCat(const AlphaNum& a, const AlphaNum& b,
const AlphaNum& c, const AlphaNum& d,
const AlphaNum& e, const AV&... args) {
return strings_internal::CatPieces(
{a.Piece(), b.Piece(), c.Piece(), d.Piece(), e.Piece(),
static_cast<const AlphaNum&>(args).Piece()...});

View File

@@ -359,8 +359,8 @@ using ParsedFormat = str_format_internal::ExtendedParsedFormat<
//
// Returns an empty string in case of error.
template <typename... Args>
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec<Args...>& format,
const Args&... args) {
[[nodiscard]] std::string StrFormat(const FormatSpec<Args...>& format,
const Args&... args) {
return str_format_internal::FormatPack(
str_format_internal::UntypedFormatSpecImpl::Extract(format),
{str_format_internal::FormatArgImpl(args)...});
@@ -396,7 +396,7 @@ std::string& StrAppendFormat(absl::Nonnull<std::string*> dst,
//
// std::cout << StreamFormat("%12.6f", 3.14);
template <typename... Args>
ABSL_MUST_USE_RESULT str_format_internal::Streamable StreamFormat(
[[nodiscard]] str_format_internal::Streamable StreamFormat(
const FormatSpec<Args...>& format, const Args&... args) {
return str_format_internal::Streamable(
str_format_internal::UntypedFormatSpecImpl::Extract(format),
@@ -582,9 +582,9 @@ using FormatArg = str_format_internal::FormatArgImpl;
// return std::move(out);
// }
//
ABSL_MUST_USE_RESULT inline bool FormatUntyped(
FormatRawSink raw_sink, const UntypedFormatSpec& format,
absl::Span<const FormatArg> args) {
[[nodiscard]] inline bool FormatUntyped(FormatRawSink raw_sink,
const UntypedFormatSpec& format,
absl::Span<const FormatArg> args) {
return str_format_internal::FormatUntyped(
str_format_internal::FormatRawSinkImpl::Extract(raw_sink),
str_format_internal::UntypedFormatSpecImpl::Extract(format), args);

View File

@@ -66,7 +66,7 @@ ABSL_NAMESPACE_BEGIN
// {"$who", "Bob"},
// {"#Noun", "Apples"}});
// EXPECT_EQ("Bob bought 5 Apples. Thanks Bob!", s);
ABSL_MUST_USE_RESULT std::string StrReplaceAll(
[[nodiscard]] std::string StrReplaceAll(
absl::string_view s,
std::initializer_list<std::pair<absl::string_view, absl::string_view>>
replacements);

View File

@@ -74,7 +74,7 @@ inline constexpr bool ConsumeSuffix(absl::Nonnull<absl::string_view*> str,
// Returns a view into the input string `str` with the given `prefix` removed,
// but leaving the original string intact. If the prefix does not match at the
// start of the string, returns the original string instead.
ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripPrefix(
[[nodiscard]] inline constexpr absl::string_view StripPrefix(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND,
absl::string_view prefix) {
if (absl::StartsWith(str, prefix)) str.remove_prefix(prefix.size());
@@ -86,7 +86,7 @@ ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripPrefix(
// Returns a view into the input string `str` with the given `suffix` removed,
// but leaving the original string intact. If the suffix does not match at the
// end of the string, returns the original string instead.
ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripSuffix(
[[nodiscard]] inline constexpr absl::string_view StripSuffix(
absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND,
absl::string_view suffix) {
if (absl::EndsWith(str, suffix)) str.remove_suffix(suffix.size());

View File

@@ -539,20 +539,20 @@ void SubstituteAndAppend(
// void VarMsg(absl::string_view format, const Args&... args) {
// std::string s = absl::Substitute(format, args...);
ABSL_MUST_USE_RESULT inline std::string Substitute(absl::string_view format) {
[[nodiscard]] inline std::string Substitute(absl::string_view format) {
std::string result;
SubstituteAndAppend(&result, format);
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0) {
std::string result;
SubstituteAndAppend(&result, format, a0);
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1) {
std::string result;
@@ -560,7 +560,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2) {
std::string result;
@@ -568,7 +568,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3) {
@@ -577,7 +577,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4) {
@@ -586,7 +586,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4,
@@ -596,7 +596,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4,
@@ -606,7 +606,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4,
@@ -617,7 +617,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4,
@@ -628,7 +628,7 @@ ABSL_MUST_USE_RESULT inline std::string Substitute(
return result;
}
ABSL_MUST_USE_RESULT inline std::string Substitute(
[[nodiscard]] inline std::string Substitute(
absl::string_view format, const substitute_internal::Arg& a0,
const substitute_internal::Arg& a1, const substitute_internal::Arg& a2,
const substitute_internal::Arg& a3, const substitute_internal::Arg& a4,

View File

@@ -190,7 +190,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED Mutex {
// If the mutex can be acquired without blocking, does so exclusively and
// returns `true`. Otherwise, returns `false`. Returns `true` with high
// probability if the `Mutex` was free.
ABSL_MUST_USE_RESULT bool TryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true);
[[nodiscard]] bool TryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true);
// Mutex::AssertHeld()
//
@@ -255,7 +255,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED Mutex {
// If the mutex can be acquired without blocking, acquires this mutex for
// shared access and returns `true`. Otherwise, returns `false`. Returns
// `true` with high probability if the `Mutex` was free or shared.
ABSL_MUST_USE_RESULT bool ReaderTryLock() ABSL_SHARED_TRYLOCK_FUNCTION(true);
[[nodiscard]] bool ReaderTryLock() ABSL_SHARED_TRYLOCK_FUNCTION(true);
// Mutex::AssertReaderHeld()
//
@@ -281,8 +281,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED Mutex {
void WriterUnlock() ABSL_UNLOCK_FUNCTION() { this->Unlock(); }
ABSL_MUST_USE_RESULT bool WriterTryLock()
ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
[[nodiscard]] bool WriterTryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
return this->TryLock();
}

View File

@@ -1357,7 +1357,7 @@ static absl::Duration TimeoutTestAllowedSchedulingDelay() {
// Returns true if `actual_delay` is close enough to `expected_delay` to pass
// the timeouts/deadlines test. Otherwise, logs warnings and returns false.
ABSL_MUST_USE_RESULT
[[nodiscard]]
static bool DelayIsWithinBounds(absl::Duration expected_delay,
absl::Duration actual_delay) {
bool pass = true;

View File

@@ -75,7 +75,7 @@ class Notification {
// Notification::HasBeenNotified()
//
// Returns the value of the notification's internal "notified" state.
ABSL_MUST_USE_RESULT bool HasBeenNotified() const {
[[nodiscard]] bool HasBeenNotified() const {
if (HasBeenNotifiedInternal(&this->notified_yet_)) {
base_internal::TraceObserved(this, TraceObjectKind());
return true;