This revision was automatically updated to reflect the committed changes. ilya-biryukov marked an inline comment as done. Closed by commit rG733777a81662: [clangd] Fix namespace aliases in findExplicitReferences (authored by ilya-biryukov).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D69624/new/ https://reviews.llvm.org/D69624 Files: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/FindTargetTests.cpp Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -882,6 +882,28 @@ "0: targets = {x}, decl\n" "1: targets = {fptr}, decl\n" "2: targets = {a}, decl\n"}, + // Namespace aliases should be handled properly. + { + R"cpp( + namespace ns { struct Type {} } + namespace alias = ns; + namespace rec_alias = alias; + + void foo() { + $0^ns::$1^Type $2^a; + $3^alias::$4^Type $5^b; + $6^rec_alias::$7^Type $8^c; + } + )cpp", + "0: targets = {ns}\n" + "1: targets = {ns::Type}, qualifier = 'ns::'\n" + "2: targets = {a}, decl\n" + "3: targets = {alias}\n" + "4: targets = {ns::Type}, qualifier = 'alias::'\n" + "5: targets = {b}, decl\n" + "6: targets = {rec_alias}\n" + "7: targets = {ns::Type}, qualifier = 'rec_alias::'\n" + "8: targets = {c}, decl\n"}, }; for (const auto &C : Cases) { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -674,10 +674,14 @@ return refInDecl(D); if (auto *E = N.get<Expr>()) return refInExpr(E); - if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) - return {ReferenceLoc{NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false, - explicitReferenceTargets(DynTypedNode::create( - *NNSL->getNestedNameSpecifier()))}}; + if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) { + // (!) 'DeclRelation::Alias' ensures we do not loose namespace aliases. + return {ReferenceLoc{ + NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false, + explicitReferenceTargets( + DynTypedNode::create(*NNSL->getNestedNameSpecifier()), + DeclRelation::Alias)}}; + } if (const TypeLoc *TL = N.get<TypeLoc>()) return refInTypeLoc(*TL); if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>()) {
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -882,6 +882,28 @@ "0: targets = {x}, decl\n" "1: targets = {fptr}, decl\n" "2: targets = {a}, decl\n"}, + // Namespace aliases should be handled properly. + { + R"cpp( + namespace ns { struct Type {} } + namespace alias = ns; + namespace rec_alias = alias; + + void foo() { + $0^ns::$1^Type $2^a; + $3^alias::$4^Type $5^b; + $6^rec_alias::$7^Type $8^c; + } + )cpp", + "0: targets = {ns}\n" + "1: targets = {ns::Type}, qualifier = 'ns::'\n" + "2: targets = {a}, decl\n" + "3: targets = {alias}\n" + "4: targets = {ns::Type}, qualifier = 'alias::'\n" + "5: targets = {b}, decl\n" + "6: targets = {rec_alias}\n" + "7: targets = {ns::Type}, qualifier = 'rec_alias::'\n" + "8: targets = {c}, decl\n"}, }; for (const auto &C : Cases) { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -674,10 +674,14 @@ return refInDecl(D); if (auto *E = N.get<Expr>()) return refInExpr(E); - if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) - return {ReferenceLoc{NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false, - explicitReferenceTargets(DynTypedNode::create( - *NNSL->getNestedNameSpecifier()))}}; + if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) { + // (!) 'DeclRelation::Alias' ensures we do not loose namespace aliases. + return {ReferenceLoc{ + NNSL->getPrefix(), NNSL->getLocalBeginLoc(), false, + explicitReferenceTargets( + DynTypedNode::create(*NNSL->getNestedNameSpecifier()), + DeclRelation::Alias)}}; + } if (const TypeLoc *TL = N.get<TypeLoc>()) return refInTypeLoc(*TL); if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits