Skip to content

Commit 37ec65e

Browse files
committed
[clangd] Enable expand-auto for decltype(auto).
Based on https://reviews.llvm.org/D116919. Fixes clangd/clangd#121 Differential Revision: https://reviews.llvm.org/D116921
1 parent 392aa97 commit 37ec65e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
9696
if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
9797
if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) {
9898
if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) {
99-
// Code in apply() does handle 'decltype(auto)' yet.
100-
if (!Result.getTypePtr()->isDecltypeAuto() &&
101-
!isStructuredBindingType(Node) &&
99+
if (!isStructuredBindingType(Node) &&
102100
!isDeducedAsLambda(Node, Result.getBeginLoc()) &&
103101
!isTemplateParam(Node))
104102
CachedLocation = Result;

clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
7171
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
7272
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
7373

74-
EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
74+
EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
75+
EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
7576
// expanding types in structured bindings is syntactically invalid.
7677
EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
7778

0 commit comments

Comments
 (0)