From 4ef5011a7b3b20703c58a1af0589e72b20812026 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Tue, 19 Sep 2017 20:34:45 -0700 Subject: [PATCH] Base: Delete ostream<< with std::string* In most reasonable cases, this is actually a bug. So delete the operator overload and let the compiler complain. Test: m Change-Id: I7d66ec2f33cc46588b6f549876241871f19ce995 --- base/include/android-base/logging.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h index 548b286c4..f18cc0ca8 100644 --- a/base/include/android-base/logging.h +++ b/base/include/android-base/logging.h @@ -438,4 +438,14 @@ class ScopedLogSeverity { } // namespace base } // namespace android +namespace std { + +// Delete << with string* to avoid mistakes. The intention was most likely to print *string. +// If you really want to print the pointer, consider static_cast. +// +// Note: for this to work, we need to have this in a namespace. +std::ostream& operator<<(std::ostream& stream, const std::string* string_pointer) = delete; + +} // namespace std + #endif // ANDROID_BASE_LOGGING_H