[PATCH] D138300: [clangd] Support type hints for `decltype(expr)`
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 19 13:10:54 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b2cf982cc51: [clangd] Support type hints for `decltype(expr)` (authored by v1nh1shungry, committed by nridge).
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.484050.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221219/c1181974/attachment.bin>
More information about the cfe-commits
mailing list