[PATCH] D150539: [clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 16 13:18:05 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa72b064acf95: [clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150539

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===================================================================
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,24 @@
                "hil = 0xABCil;",
                Style);
 
+  verifyFormat("bd = 0b1'0000d;\n"
+               "dh = 1'234h;\n"
+               "dmin = 1'234min;\n"
+               "dns = 1'234ns;\n"
+               "ds = 1'234s;\n"
+               "dus = 1'234us;\n"
+               "hy = 0xA'BCy;",
+               "bd = 0b10000d;\n"
+               "dh = 1234h;\n"
+               "dmin = 1234min;\n"
+               "dns = 1234ns;\n"
+               "ds = 1234s;\n"
+               "dus = 1234us;\n"
+               "hy = 0xABCy;",
+               Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
                "h = 0xD'EF_u16;",
                "d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@
       continue;
     }
     if (Style.isCpp()) {
-      if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+      // Hex alpha digits a-f/A-F must be at the end of the string literal.
+      StringRef Suffixes = "_himnsuyd";
+      if (const auto Pos =
+              Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+          Pos != StringRef::npos) {
         Text = Text.substr(0, Pos);
         Length = Pos;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150539.522756.patch
Type: text/x-patch
Size: 1706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230516/6b93a92e/attachment.bin>


More information about the cfe-commits mailing list