[PATCH] D138300: [clangd] Support type hints for `decltype(expr)`
Vincent Hong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 16 21:59:38 PST 2022
v1nh1shungry updated this revision to Diff 483720.
v1nh1shungry added a comment.
reimplement and address review's suggestions
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138300/new/
https://reviews.llvm.org/D138300
Files:
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1361,6 +1361,29 @@
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
}
+TEST(TypeHints, Decltype) {
+ assertTypeHints(R"cpp(
+ $a[[decltype(0)]] a;
+ // FIXME: will be nice to show `: int` instead
+ $b[[decltype(a)]] b;
+ const $c[[decltype(0)]] &c = b;
+
+ // Don't show for dependent type
+ template <class T>
+ constexpr decltype(T{}) d;
+
+ $e[[decltype(0)]] e();
+ auto f() -> $f[[decltype(0)]];
+
+ template <class, class> struct Foo;
+ using G = Foo<$g[[decltype(0)]], float>;
+ )cpp",
+ ExpectedHint{": int", "a"},
+ ExpectedHint{": decltype(0)", "b"},
+ ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
+ ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"});
+}
+
TEST(DesignatorHints, Basic) {
assertDesignatorHints(R"cpp(
struct S { int x, y, z; };
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -218,6 +218,13 @@
StructuredBindingPolicy.PrintCanonicalTypes = true;
}
+ bool VisitTypeLoc(TypeLoc TL) {
+ if (const auto *DT = llvm::dyn_cast<DecltypeType>(TL.getType()))
+ if (QualType UT = DT->getUnderlyingType(); !UT->isDependentType())
+ addTypeHint(TL.getSourceRange(), UT, ": ");
+ return true;
+ }
+
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
// Weed out constructor calls that don't look like a function call with
// an argument list, by checking the validity of getParenOrBraceRange().
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138300.483720.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221217/6a0bc6c4/attachment.bin>
More information about the cfe-commits
mailing list