[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.
Viktoriia Bakalova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 15 05:44:24 PDT 2023
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153015
Files:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3722,6 +3722,18 @@
EXPECT_EQ(*HI->Value, "&bar");
}
+TEST(Hover, FunctionParameterDefaulValueNotEvaluated) {
+ Annotations T(R"cpp(
+ void foo(int p^aram = 5);
+ )cpp");
+
+ TestTU TU = TestTU::withCode(T.code());
+ auto AST = TU.build();
+ auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ ASSERT_TRUE(HI);
+ ASSERT_FALSE(HI->Value);
+}
+
TEST(Hover, DisableShowAKA) {
Annotations T(R"cpp(
using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,8 @@
HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
// Fill in value with evaluated initializer if possible.
- if (const auto *Var = dyn_cast<VarDecl>(D)) {
+ const auto *Var = dyn_cast<VarDecl>(D);
+ if (Var != nullptr && !llvm::isa<ParmVarDecl>(Var)) {
if (const Expr *Init = Var->getInit())
HI.Value = printExprValue(Init, Ctx);
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153015.531715.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230615/7b0126ae/attachment.bin>
More information about the cfe-commits
mailing list