hokein created this revision. hokein added a reviewer: sammccall. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D65067 Files: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp clang-tools-extra/clangd/unittests/TweakTests.cpp Index: clang-tools-extra/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ 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 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 @@ -60,9 +60,12 @@ CachedLocation = llvm::None; if (auto *Node = Inputs.ASTSelection.commonAncestor()) { if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) { - if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) { + auto Node = *TypeNode; + // Skip any qualifiers (e.g. const) around auto. + if (const auto QTL = Node.getAs<QualifiedTypeLoc>()) + Node = QTL.getUnqualifiedLoc(); + if (const AutoTypeLoc Result = Node.getAs<AutoTypeLoc>()) CachedLocation = Result; - } } } return (bool) CachedLocation;
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ 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 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 @@ -60,9 +60,12 @@ CachedLocation = llvm::None; if (auto *Node = Inputs.ASTSelection.commonAncestor()) { if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) { - if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) { + auto Node = *TypeNode; + // Skip any qualifiers (e.g. const) around auto. + if (const auto QTL = Node.getAs<QualifiedTypeLoc>()) + Node = QTL.getUnqualifiedLoc(); + if (const AutoTypeLoc Result = Node.getAs<AutoTypeLoc>()) CachedLocation = Result; - } } } return (bool) CachedLocation;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits