[clang-tools-extra] efeb65d - Fix up clangd after Clang 038edf6029bafe70b1f7165abe2b0e61ddf506b3.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 16:36:36 PDT 2020


Author: Richard Smith
Date: 2020-08-20T16:36:25-07:00
New Revision: efeb65d53b88d9c3ac3a185c396efd8db8c9f7d9

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

LOG: Fix up clangd after Clang 038edf6029bafe70b1f7165abe2b0e61ddf506b3.

Now that Clang is able to constant-evaluate void-typed expressions,
disable showing hover-card values for them. It's not useful to say that
an expression cast to void has value '<no value>', even if we can
constant-evaluate it to that result!

Added: 
    

Modified: 
    clang-tools-extra/clangd/Hover.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 8305a4724035..ef9bb536005f 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -339,10 +339,11 @@ llvm::Optional<std::string> printExprValue(const Expr *E,
   }
 
   // Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
-  // to the enclosing call.
+  // to the enclosing call. Evaluating an expression of void type doesn't
+  // produce a meaningful result.
   QualType T = E->getType();
   if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
-      T->isFunctionReferenceType())
+      T->isFunctionReferenceType() || T->isVoidType())
     return llvm::None;
 
   Expr::EvalResult Constant;
@@ -370,6 +371,10 @@ llvm::Optional<std::string> printExprValue(const SelectionTree::Node *N,
   for (; N; N = N->Parent) {
     // Try to evaluate the first evaluatable enclosing expression.
     if (const Expr *E = N->ASTNode.get<Expr>()) {
+      // Once we cross an expression of type 'cv void', the evaluated result
+      // has nothing to do with our original cursor position.
+      if (!E->getType().isNull() && E->getType()->isVoidType())
+        break;
       if (auto Val = printExprValue(E, Ctx))
         return Val;
     } else if (N->ASTNode.get<Decl>() || N->ASTNode.get<Stmt>()) {


        


More information about the cfe-commits mailing list