ilya-biryukov created this revision. ilya-biryukov added reviewers: kadircet, sammccall. Herald added subscribers: arphaman, jkorous, MaskRay, ioeric. Herald added a project: clang.
The assertion checking that the range of the node is a token range does not hold in case of "split" tokens, e.g. between two closing template argument lists (vector<vector<int>>). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D58447 Files: clang-tools-extra/clangd/Selection.cpp clang-tools-extra/unittests/clangd/SelectionTests.cpp Index: clang-tools-extra/unittests/clangd/SelectionTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/SelectionTests.cpp +++ clang-tools-extra/unittests/clangd/SelectionTests.cpp @@ -232,6 +232,11 @@ }]]]] } )cpp", + R"cpp( + template <class T> + struct unique_ptr {} + void foo(^$C[[unique_ptr<unique_ptr<$C[[int]]>>]]^ a) {} + )cpp", }; for (const char *C : Cases) { Annotations Test(C); Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -198,11 +198,10 @@ auto E = SM.getDecomposedLoc(R.getEnd()); if (B.first != SelFile || E.first != SelFile) continue; - assert(R.isTokenRange()); // Try to cover up to the next token, spaces between children don't count. if (auto Tok = Lexer::findNextToken(R.getEnd(), SM, LangOpts)) E.second = SM.getFileOffset(Tok->getLocation()); - else + else if (R.isTokenRange()) E.second += Lexer::MeasureTokenLength(R.getEnd(), SM, LangOpts); ChildRanges.push_back({B.second, E.second}); }
Index: clang-tools-extra/unittests/clangd/SelectionTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/SelectionTests.cpp +++ clang-tools-extra/unittests/clangd/SelectionTests.cpp @@ -232,6 +232,11 @@ }]]]] } )cpp", + R"cpp( + template <class T> + struct unique_ptr {} + void foo(^$C[[unique_ptr<unique_ptr<$C[[int]]>>]]^ a) {} + )cpp", }; for (const char *C : Cases) { Annotations Test(C); Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -198,11 +198,10 @@ auto E = SM.getDecomposedLoc(R.getEnd()); if (B.first != SelFile || E.first != SelFile) continue; - assert(R.isTokenRange()); // Try to cover up to the next token, spaces between children don't count. if (auto Tok = Lexer::findNextToken(R.getEnd(), SM, LangOpts)) E.second = SM.getFileOffset(Tok->getLocation()); - else + else if (R.isTokenRange()) E.second += Lexer::MeasureTokenLength(R.getEnd(), SM, LangOpts); ChildRanges.push_back({B.second, E.second}); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits