[PATCH] D142440: [clangd] Don't show 'auto' type hint when type deduction fails
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 29 22:21:28 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG68d7f69001c5: [clangd] Don't show 'auto' type hint when type deduction fails (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142440/new/
https://reviews.llvm.org/D142440
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
@@ -1256,6 +1256,13 @@
)cpp");
}
+TEST(TypeHints, InvalidType) {
+ assertTypeHints(R"cpp(
+ auto x = (unknown_type)42; /*error-ok*/
+ auto *y = (unknown_ptr)nullptr;
+ )cpp");
+}
+
TEST(TypeHints, ReturnTypeDeduction) {
assertTypeHints(
R"cpp(
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -304,8 +304,8 @@
return true;
}
- if (D->getType()->getContainedAutoType()) {
- if (!D->getType()->isDependentType()) {
+ if (auto *AT = D->getType()->getContainedAutoType()) {
+ if (AT->isDeduced() && !D->getType()->isDependentType()) {
// Our current approach is to place the hint on the variable
// and accordingly print the full type
// (e.g. for `const auto& x = 42`, print `const int&`).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142440.493204.patch
Type: text/x-patch
Size: 1171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230130/a3b26c14/attachment-0001.bin>
More information about the cfe-commits
mailing list