[PATCH] D146501: [clang-format] Don't format already formatted integer literals

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 26 13:25:51 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b5c49ad4563: [clang-format] Don't format already formatted integer literals (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146501

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp


Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -130,13 +130,12 @@
       DigitsPerGroup = Hex;
     if (DigitsPerGroup > 0 && checkSeparator(Text, DigitsPerGroup))
       continue;
+    const auto &Formatted = format(Text, DigitsPerGroup);
+    assert(Formatted != Text);
     if (Start > 0)
       Location = Location.getLocWithOffset(Start);
-    if (const auto &Formatted = format(Text, DigitsPerGroup);
-        Formatted != Text) {
-      cantFail(Result.add(
-          tooling::Replacement(SourceMgr, Location, Length, Formatted)));
-    }
+    cantFail(Result.add(
+        tooling::Replacement(SourceMgr, Location, Length, Formatted)));
   }
 
   return {Result, 0};
@@ -153,9 +152,9 @@
         return false;
       I = 0;
     } else {
-      ++I;
       if (I == DigitsPerGroup)
         return false;
+      ++I;
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146501.508439.patch
Type: text/x-patch
Size: 1029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230326/58525f04/attachment.bin>


More information about the cfe-commits mailing list