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

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 09:08:56 PDT 2020


njames93 updated this revision to Diff 249121.
njames93 added a comment.

- Removed template in favour of specific overloads


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75714/new/

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"
@@ -1288,6 +1289,45 @@
   return DB;
 }
 
+inline const DiagnosticBuilder &
+operator<<(const DiagnosticBuilder &DB,
+           const llvm::Optional<SourceRange> &Opt) {
+  if (Opt)
+    DB << *Opt;
+  return DB;
+};
+
+inline const DiagnosticBuilder &
+operator<<(const DiagnosticBuilder &DB,
+           const llvm::Optional<ArrayRef<SourceRange>> &Opt) {
+  if (Opt)
+    DB << *Opt;
+  return DB;
+};
+
+inline const DiagnosticBuilder &
+operator<<(const DiagnosticBuilder &DB,
+           const llvm::Optional<CharSourceRange> &Opt) {
+  if (Opt)
+    DB << *Opt;
+  return DB;
+};
+
+inline const DiagnosticBuilder &
+operator<<(const DiagnosticBuilder &DB, const llvm::Optional<FixItHint> &Opt) {
+  if (Opt)
+    DB << *Opt;
+  return DB;
+};
+
+inline const DiagnosticBuilder &
+operator<<(const DiagnosticBuilder &DB,
+           const llvm::Optional<ArrayRef<FixItHint>> &Opt) {
+  if (Opt)
+    DB << *Opt;
+  return DB;
+};
+
 /// A nullability kind paired with a bit indicating whether it used a
 /// context-sensitive keyword.
 using DiagNullabilityKind = std::pair<NullabilityKind, bool>;


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


More information about the cfe-commits mailing list