diff options
author | Haojian Wu <hokein@google.com> | 2018-08-01 11:24:50 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2018-08-01 11:24:50 +0000 |
commit | 187ca5ee2304b14b3bc71bca4efb334d02ef599b (patch) | |
tree | 0d438955109ef5abf1913ff2dc0bef3fa8ce0438 | |
parent | a84c88dbafbe4991c14a2ae8747a9c1cd437444f (diff) |
[clangd] Make SymbolLocation => bool conversion explicitly.
Summary:
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).
Reviewers: sammccall
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D49657
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@338517 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | clangd/index/Index.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clangd/index/Index.h b/clangd/index/Index.h index 0fda5ad1..18ed05f7 100644 --- a/clangd/index/Index.h +++ b/clangd/index/Index.h @@ -30,6 +30,9 @@ struct SymbolLocation { 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 @@ struct SymbolLocation { 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 &); |