Skip to content

Commit efeb65d

Browse files
committed
Fix up clangd after Clang 038edf6.
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!
1 parent 1f3c92f commit efeb65d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang-tools-extra/clangd/Hover.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ llvm::Optional<std::string> printExprValue(const Expr *E,
339339
}
340340

341341
// Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
342-
// to the enclosing call.
342+
// to the enclosing call. Evaluating an expression of void type doesn't
343+
// produce a meaningful result.
343344
QualType T = E->getType();
344345
if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
345-
T->isFunctionReferenceType())
346+
T->isFunctionReferenceType() || T->isVoidType())
346347
return llvm::None;
347348

348349
Expr::EvalResult Constant;
@@ -370,6 +371,10 @@ llvm::Optional<std::string> printExprValue(const SelectionTree::Node *N,
370371
for (; N; N = N->Parent) {
371372
// Try to evaluate the first evaluatable enclosing expression.
372373
if (const Expr *E = N->ASTNode.get<Expr>()) {
374+
// Once we cross an expression of type 'cv void', the evaluated result
375+
// has nothing to do with our original cursor position.
376+
if (!E->getType().isNull() && E->getType()->isVoidType())
377+
break;
373378
if (auto Val = printExprValue(E, Ctx))
374379
return Val;
375380
} else if (N->ASTNode.get<Decl>() || N->ASTNode.get<Stmt>()) {

0 commit comments

Comments
 (0)