Skip to content

Commit 8f739d1

Browse files
suertreuscopybara-github
authored andcommitted
Add ABSL_ATTRIBUTE_LIFETIME_BOUND and a doc note about absl::LogAsLiteral to clarify its intended use.
PiperOrigin-RevId: 696592874 Change-Id: I6d6bc4690f891fbbdd8489b2e2f6398b43d63001
1 parent c313056 commit 8f739d1

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

absl/log/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ cc_library(
234234
linkopts = ABSL_DEFAULT_LINKOPTS,
235235
deps = [
236236
"//absl/base:config",
237+
"//absl/base:core_headers",
237238
"//absl/log/internal:structured",
238239
"//absl/strings",
239240
],

absl/log/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ absl_cc_library(
665665
${ABSL_DEFAULT_LINKOPTS}
666666
DEPS
667667
absl::config
668+
absl::core_headers
668669
absl::log_internal_message
669670
absl::strings
670671
)
@@ -680,6 +681,7 @@ absl_cc_library(
680681
${ABSL_DEFAULT_LINKOPTS}
681682
DEPS
682683
absl::config
684+
absl::core_headers
683685
absl::log_internal_structured
684686
absl::strings
685687
PUBLIC

absl/log/internal/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ cc_library(
281281
deps = [
282282
":log_message",
283283
"//absl/base:config",
284+
"//absl/base:core_headers",
284285
"//absl/strings",
285286
],
286287
)

absl/log/internal/structured.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <ostream>
2323

2424
#include "absl/base/config.h"
25+
#include "absl/base/attributes.h"
2526
#include "absl/log/internal/log_message.h"
2627
#include "absl/strings/string_view.h"
2728

@@ -31,14 +32,16 @@ namespace log_internal {
3132

3233
class ABSL_MUST_USE_RESULT AsLiteralImpl final {
3334
public:
34-
explicit AsLiteralImpl(absl::string_view str) : str_(str) {}
35+
explicit AsLiteralImpl(absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND)
36+
: str_(str) {}
3537
AsLiteralImpl(const AsLiteralImpl&) = default;
3638
AsLiteralImpl& operator=(const AsLiteralImpl&) = default;
3739

3840
private:
3941
absl::string_view str_;
4042

41-
friend std::ostream& operator<<(std::ostream& os, AsLiteralImpl as_literal) {
43+
friend std::ostream& operator<<(std::ostream& os,
44+
AsLiteralImpl&& as_literal) {
4245
return os << as_literal.str_;
4346
}
4447
void AddToMessage(log_internal::LogMessage& m) {

absl/log/structured.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <ostream>
3434

35+
#include "absl/base/attributes.h"
3536
#include "absl/base/config.h"
3637
#include "absl/log/internal/structured.h"
3738
#include "absl/strings/string_view.h"
@@ -60,7 +61,11 @@ ABSL_NAMESPACE_BEGIN
6061
// int line) {
6162
// LOG(LEVEL(severity)).AtLocation(file, line) << absl::LogAsLiteral(str);
6263
// }
63-
inline log_internal::AsLiteralImpl LogAsLiteral(absl::string_view s) {
64+
//
65+
// `LogAsLiteral` should only be used as a streaming operand and not, for
66+
// example, as a local variable initializer.
67+
inline log_internal::AsLiteralImpl LogAsLiteral(
68+
absl::string_view s ABSL_ATTRIBUTE_LIFETIME_BOUND) {
6469
return log_internal::AsLiteralImpl(s);
6570
}
6671

0 commit comments

Comments
 (0)