[clang-tools-extra] 37ec65e - [clangd] Enable expand-auto for decltype(auto).
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 10 04:49:10 PST 2022
Author: Haojian Wu
Date: 2022-01-10T13:46:56+01:00
New Revision: 37ec65e1d705f56fe5551de1dfcbac1e071588a2
URL: https://github.com/llvm/llvm-project/commit/37ec65e1d705f56fe5551de1dfcbac1e071588a2
DIFF: https://github.com/llvm/llvm-project/commit/37ec65e1d705f56fe5551de1dfcbac1e071588a2.diff
LOG: [clangd] Enable expand-auto for decltype(auto).
Based on https://reviews.llvm.org/D116919.
Fixes https://github.com/clangd/clangd/issues/121
Differential Revision: https://reviews.llvm.org/D116921
Added:
Modified:
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 3776e1c3505d1..914564e9ae218 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,9 +96,7 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) {
if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) {
- // Code in apply() does handle 'decltype(auto)' yet.
- if (!Result.getTypePtr()->isDecltypeAuto() &&
- !isStructuredBindingType(Node) &&
+ if (!isStructuredBindingType(Node) &&
!isDeducedAsLambda(Node, Result.getBeginLoc()) &&
!isTemplateParam(Node))
CachedLocation = Result;
diff --git a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
index 96574a67b5a46..6d9d4362be7af 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,7 +71,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
- EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+ EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
+ EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
// expanding types in structured bindings is syntactically invalid.
EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
More information about the cfe-commits
mailing list