kadircet updated this revision to Diff 401178. kadircet marked an inline comment as done. kadircet added a comment.
- Store in vector and sort Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117549/new/ https://reviews.llvm.org/D117549 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 @@ -1283,11 +1283,7 @@ "0: targets = {x}, decl\n" "1: targets = {vector}\n" "2: targets = {x}\n"}, -// Handle UnresolvedLookupExpr. -// FIXME -// This case fails when expensive checks are enabled. -// Seems like the order of ns1::func and ns2::func isn't defined. -#ifndef EXPENSIVE_CHECKS + // Handle UnresolvedLookupExpr. {R"cpp( namespace ns1 { void func(char*); } namespace ns2 { void func(int*); } @@ -1301,7 +1297,6 @@ )cpp", "0: targets = {ns1::func, ns2::func}\n" "1: targets = {t}\n"}, -#endif // Handle UnresolvedMemberExpr. {R"cpp( struct X { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -33,13 +33,16 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" #include <iterator> +#include <string> #include <utility> #include <vector> @@ -1169,14 +1172,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceLoc R) { // note we cannot print R.NameLoc without a source manager. OS << "targets = {"; - bool First = true; + llvm::SmallVector<std::string> Targets; for (const NamedDecl *T : R.Targets) { - if (!First) - OS << ", "; - else - First = false; - OS << printQualifiedName(*T) << printTemplateSpecializationArgs(*T); + llvm::raw_string_ostream Target(Targets.emplace_back()); + Target << printQualifiedName(*T) << printTemplateSpecializationArgs(*T); } + llvm::sort(Targets); + OS << llvm::join(Targets, ", "); OS << "}"; if (R.Qualifier) { OS << ", qualifier = '";
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -1283,11 +1283,7 @@ "0: targets = {x}, decl\n" "1: targets = {vector}\n" "2: targets = {x}\n"}, -// Handle UnresolvedLookupExpr. -// FIXME -// This case fails when expensive checks are enabled. -// Seems like the order of ns1::func and ns2::func isn't defined. -#ifndef EXPENSIVE_CHECKS + // Handle UnresolvedLookupExpr. {R"cpp( namespace ns1 { void func(char*); } namespace ns2 { void func(int*); } @@ -1301,7 +1297,6 @@ )cpp", "0: targets = {ns1::func, ns2::func}\n" "1: targets = {t}\n"}, -#endif // Handle UnresolvedMemberExpr. {R"cpp( struct X { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -33,13 +33,16 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" #include <iterator> +#include <string> #include <utility> #include <vector> @@ -1169,14 +1172,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, ReferenceLoc R) { // note we cannot print R.NameLoc without a source manager. OS << "targets = {"; - bool First = true; + llvm::SmallVector<std::string> Targets; for (const NamedDecl *T : R.Targets) { - if (!First) - OS << ", "; - else - First = false; - OS << printQualifiedName(*T) << printTemplateSpecializationArgs(*T); + llvm::raw_string_ostream Target(Targets.emplace_back()); + Target << printQualifiedName(*T) << printTemplateSpecializationArgs(*T); } + llvm::sort(Targets); + OS << llvm::join(Targets, ", "); OS << "}"; if (R.Qualifier) { OS << ", qualifier = '";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits