mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Add ABSL_ATTRIBUTE_LIFETIME_BOUND and a doc note about absl::LogAsLiteral to clarify its intended use.
PiperOrigin-RevId: 696592874 Change-Id: I6d6bc4690f891fbbdd8489b2e2f6398b43d63001
This commit is contained in:
committed by
Copybara-Service
parent
c31305634b
commit
8f739d18b9
@@ -234,6 +234,7 @@ cc_library(
|
||||
linkopts = ABSL_DEFAULT_LINKOPTS,
|
||||
deps = [
|
||||
"//absl/base:config",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/log/internal:structured",
|
||||
"//absl/strings",
|
||||
],
|
||||
|
||||
@@ -665,6 +665,7 @@ absl_cc_library(
|
||||
${ABSL_DEFAULT_LINKOPTS}
|
||||
DEPS
|
||||
absl::config
|
||||
absl::core_headers
|
||||
absl::log_internal_message
|
||||
absl::strings
|
||||
)
|
||||
@@ -680,6 +681,7 @@ absl_cc_library(
|
||||
${ABSL_DEFAULT_LINKOPTS}
|
||||
DEPS
|
||||
absl::config
|
||||
absl::core_headers
|
||||
absl::log_internal_structured
|
||||
absl::strings
|
||||
PUBLIC
|
||||
|
||||
@@ -281,6 +281,7 @@ cc_library(
|
||||
deps = [
|
||||
":log_message",
|
||||
"//absl/base:config",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <ostream>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/log/internal/log_message.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
@@ -31,14 +32,16 @@ namespace log_internal {
|
||||
|
||||
class ABSL_MUST_USE_RESULT AsLiteralImpl final {
|
||||
public:
|
||||
explicit AsLiteralImpl(absl::string_view str) : str_(str) {}
|
||||
explicit AsLiteralImpl(absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND)
|
||||
: str_(str) {}
|
||||
AsLiteralImpl(const AsLiteralImpl&) = default;
|
||||
AsLiteralImpl& operator=(const AsLiteralImpl&) = default;
|
||||
|
||||
private:
|
||||
absl::string_view str_;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, AsLiteralImpl as_literal) {
|
||||
friend std::ostream& operator<<(std::ostream& os,
|
||||
AsLiteralImpl&& as_literal) {
|
||||
return os << as_literal.str_;
|
||||
}
|
||||
void AddToMessage(log_internal::LogMessage& m) {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/log/internal/structured.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -60,7 +61,11 @@ ABSL_NAMESPACE_BEGIN
|
||||
// int line) {
|
||||
// LOG(LEVEL(severity)).AtLocation(file, line) << absl::LogAsLiteral(str);
|
||||
// }
|
||||
inline log_internal::AsLiteralImpl LogAsLiteral(absl::string_view s) {
|
||||
//
|
||||
// `LogAsLiteral` should only be used as a streaming operand and not, for
|
||||
// example, as a local variable initializer.
|
||||
inline log_internal::AsLiteralImpl LogAsLiteral(
|
||||
absl::string_view s ABSL_ATTRIBUTE_LIFETIME_BOUND) {
|
||||
return log_internal::AsLiteralImpl(s);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user