[PATCH] D49657: [clangd] Make SymbolLocation => bool conversion explicitly.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 22 23:38:29 PDT 2018


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: arphaman, jkorous, MaskRay, ioeric, ilya-biryukov.

The implicit bool conversion could happen superisingly, e.g. when
checking `if (Loc1 == Loc2)`, the compiler will convert SymbolLocation to
bool before comparing (because we don't define operator `==` for SymbolLocation).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49657

Files:
  clangd/index/Index.h


Index: clangd/index/Index.h
===================================================================
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -30,6 +30,9 @@
     uint32_t Line = 0; // 0-based
     // Using UTF-16 code units.
     uint32_t Column = 0; // 0-based
+    bool operator==(const Position& P) const {
+      return Line == P.Line && Column == P.Column;
+    }
   };
 
   // The URI of the source file where a symbol occurs.
@@ -39,7 +42,11 @@
   Position Start;
   Position End;
 
-  operator bool() const { return !FileURI.empty(); }
+  explicit operator bool() const { return !FileURI.empty(); }
+  bool operator==(const SymbolLocation& Loc) const {
+    return std::tie(FileURI, Start, End) ==
+           std::tie(Loc.FileURI, Loc.Start, Loc.End);
+  }
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49657.156723.patch
Type: text/x-patch
Size: 856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180723/b00580dd/attachment.bin>


More information about the cfe-commits mailing list