diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp @@ -60,9 +60,12 @@ CachedLocation = llvm::None; if (auto *Node = Inputs.ASTSelection.commonAncestor()) { if (auto *TypeNode = Node->ASTNode.get()) { - if (const AutoTypeLoc Result = TypeNode->getAs()) { + auto Node = *TypeNode; + // Skip any qualifiers (e.g. const) around auto. + if (const auto QTL = Node.getAs()) + Node = QTL.getUnqualifiedLoc(); + if (const AutoTypeLoc Result = Node.getAs()) CachedLocation = Result; - } } } return (bool) CachedLocation; diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp --- a/clang-tools-extra/clangd/unittests/TweakTests.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -663,6 +663,35 @@ const char * x = "test"; )cpp"; checkTransform(ID, Input, Output); + + // qualified auto type + Input = R"cpp( + class Foo {}; + const au^to x = Foo(); + )cpp"; + Output = R"cpp( + class Foo {}; + const Foo x = Foo(); + )cpp"; + checkTransform(ID, Input, Output); + + Input = R"cpp( + volatile au^to x = 1; + )cpp"; + Output = R"cpp( + volatile int x = 1; + )cpp"; + checkTransform(ID, Input, Output); + + Input = R"cpp( + class Foo {}; + const au^to *x = new Foo(); + )cpp"; + Output = R"cpp( + class Foo {}; + const Foo *x = new Foo(); + )cpp"; + checkTransform(ID, Input, Output); } } // namespace