[PATCH] D94719: [clangd] Make ExpandAutoType not available on template params.
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 15 05:26:08 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaeaeb9e6bdc9: [clangd] Make ExpandAutoType not available on template params. (authored by adamcz).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94719/new/
https://reviews.llvm.org/D94719
Files:
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -80,6 +80,9 @@
// unknown types in a template should not be replaced
EXPECT_THAT(apply("template <typename T> void x() { ^auto y = T::z(); }"),
StartsWith("fail: Could not deduce type for 'auto' type"));
+
+ ExtraArgs.push_back("-std=c++17");
+ EXPECT_UNAVAILABLE("template <au^to X> class Y;");
}
} // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -82,6 +82,15 @@
return false;
}
+// Returns true iff "auto" in Node is really part of the template parameter,
+// which we cannot expand.
+bool isTemplateParam(const SelectionTree::Node *Node) {
+ if (Node->Parent)
+ if (Node->Parent->ASTNode.get<NonTypeTemplateParmDecl>())
+ return true;
+ return false;
+}
+
bool ExpandAutoType::prepare(const Selection& Inputs) {
CachedLocation = llvm::None;
if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
@@ -90,7 +99,8 @@
// Code in apply() does handle 'decltype(auto)' yet.
if (!Result.getTypePtr()->isDecltypeAuto() &&
!isStructuredBindingType(Node) &&
- !isDeducedAsLambda(Node, Result.getBeginLoc()))
+ !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
+ !isTemplateParam(Node))
CachedLocation = Result;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94719.316911.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210115/d46b4ef8/attachment.bin>
More information about the cfe-commits
mailing list