[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 11 06:44:17 PST 2022


aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from some nits, though please wait for @Quuxplusone to respond before landing.



================
Comment at: clang/lib/Sema/SemaLookup.cpp:4310-4311
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-    std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-    for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
-         RI != RIEnd; ++RI) {
-      // If the Correction refers to a decl already in the result list,
-      // replace the existing result if the string representation of Correction
-      // comes before the current result alphabetically, then stop as there is
-      // nothing more to be done to add Correction to the candidate set.
-      if (RI->getCorrectionDecl() == NewND) {
-        if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-          *RI = Correction;
-        return;
-      }
+    auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &typoCorr) {
+      return typoCorr.getCorrectionDecl() == NewND;
+    });
----------------



================
Comment at: clang/lib/Sema/SemaLookup.cpp:4317
+
+      auto IsDeprecated = [](Decl *decl) {
+        while (decl) {
----------------
Feel free to pick a better name than `D` (other than `Decl`, please!), just cleaning up the coding style nit.


================
Comment at: clang/lib/Sema/SemaLookup.cpp:4327
+      // Prefer non deprecated Corrections over deprecated and only then
+      // sort using an alphabetical order
+      std::pair<bool, std::string> newKey = {
----------------



================
Comment at: clang/lib/Sema/SemaLookup.cpp:4328-4332
+      std::pair<bool, std::string> newKey = {
+          IsDeprecated(Correction.getFoundDecl()),
+          Correction.getAsString(SemaRef.getLangOpts())};
+
+      std::pair<bool, std::string> prevKey = {
----------------



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116775/new/

https://reviews.llvm.org/D116775



More information about the cfe-commits mailing list