[PATCH] D75714: Add Optional overload to DiagnosticBuilder operator <<

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 5 16:26:31 PST 2020


njames93 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75714

Files:
  clang/include/clang/Basic/Diagnostic.h


Index: clang/include/clang/Basic/Diagnostic.h
===================================================================
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
@@ -1311,6 +1312,15 @@
   return DB;
 }
 
+template <typename T>
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           const llvm::Optional<T> &Opt) {
+  if (Opt) {
+    DB << *Opt;
+  }
+  return DB;
+}
+
 inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
   return Report(SourceLocation(), DiagID);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75714.248625.patch
Type: text/x-patch
Size: 849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200306/ca285a7f/attachment.bin>


More information about the cfe-commits mailing list