Fix up clangd after Clang 038edf6029.

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!
This commit is contained in:
Richard Smith 2020-08-20 16:34:48 -07:00
parent 1f3c92f968
commit efeb65d53b
1 changed files with 7 additions and 2 deletions

View File

@ -339,10 +339,11 @@ llvm::Optional<std::string> printExprValue(const Expr *E,
} }
// Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up // 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(); QualType T = E->getType();
if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() || if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
T->isFunctionReferenceType()) T->isFunctionReferenceType() || T->isVoidType())
return llvm::None; return llvm::None;
Expr::EvalResult Constant; Expr::EvalResult Constant;
@ -370,6 +371,10 @@ llvm::Optional<std::string> printExprValue(const SelectionTree::Node *N,
for (; N; N = N->Parent) { for (; N; N = N->Parent) {
// Try to evaluate the first evaluatable enclosing expression. // Try to evaluate the first evaluatable enclosing expression.
if (const Expr *E = N->ASTNode.get<Expr>()) { 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)) if (auto Val = printExprValue(E, Ctx))
return Val; return Val;
} else if (N->ASTNode.get<Decl>() || N->ASTNode.get<Stmt>()) { } else if (N->ASTNode.get<Decl>() || N->ASTNode.get<Stmt>()) {