[clang-tools-extra] cb9d0e8 - [clangd][NFC] Make Located::operator->() use pointer sematics

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 17:36:21 PST 2020


Author: Nathan James
Date: 2020-11-04T01:36:14Z
New Revision: cb9d0e8819ad7ca2f349a57d62ea2af02d631dfa

URL: https://github.com/llvm/llvm-project/commit/cb9d0e8819ad7ca2f349a57d62ea2af02d631dfa
DIFF: https://github.com/llvm/llvm-project/commit/cb9d0e8819ad7ca2f349a57d62ea2af02d631dfa.diff

LOG: [clangd][NFC] Make Located::operator->() use pointer sematics

This enables using the arrow operator to access members of the contained item.
```lang=c++
Located<std::string> X;
const char* CStr = X->c_str();
```
This is inline with how classes like `Optional` handle the arrow operator.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90682

Added: 
    

Modified: 
    clang-tools-extra/clangd/ConfigFragment.h

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h
index 7e07e9d065b3..65772715095f 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -51,8 +51,8 @@ template <typename T> struct Located {
       : Range(Range), Value(std::move(Value)) {}
 
   llvm::SMRange Range;
-  T &operator->() { return Value; }
-  const T &operator->() const { return Value; }
+  T *operator->() { return &Value; }
+  const T *operator->() const { return &Value; }
   T &operator*() { return Value; }
   const T &operator*() const { return Value; }
 


        


More information about the cfe-commits mailing list