From 7beaabc934e13d7bf32e3d46ec438885eefdefe2 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:44:00 -0700 Subject: [PATCH] Prevent ostream << for pointers to printable types. (#837) Co-authored-by: Geoff Romer --- common/ostream.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/ostream.h b/common/ostream.h index c430fbfbbfd8..1920a82493c5 100644 --- a/common/ostream.h +++ b/common/ostream.h @@ -18,6 +18,14 @@ auto operator<<(llvm::raw_ostream& out, const T& obj) -> llvm::raw_ostream& { return out; } +// Prevents ostream << for pointers to printable types. +template ::value>::type* = nullptr> +__attribute__((unavailable( + "Received a pointer to a printable type, are you missing a `*`? " + "To print as a pointer, cast to void*."))) auto +operator<<(llvm::raw_ostream& out, const T* /*obj*/) -> llvm::raw_ostream&; + } // namespace Carbon #endif // COMMON_OSTREAM_H_