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

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 14 23:09:32 PDT 2023


owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

Fixes https://github.com/llvm/llvm-project/issues/62679.


Repository:
  rG LLVM Github Monorepo

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,20 @@
                "hil = 0xABCil;",
                Style);
 
+  verifyFormat("bh = 0b1'0000h;\n"
+               "dmin = 1'234min;\n"
+               "dns = 1'234ns;\n"
+               "ds = 1'234s;\n"
+               "dus = 1'234us;\n"
+               "hy = 0xA'BCy;",
+               "bh = 0b10000h;\n"
+               "dmin = 1234min;\n"
+               "dns = 1234ns;\n"
+               "ds = 1234s;\n"
+               "dus = 1234us;\n"
+               "hy = 0xABCy;",
+               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,9 @@
       continue;
     }
     if (Style.isCpp()) {
-      if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+      // FIXME: This doesn't work for ud-suffix d from std::chrono::day.
+      if (const auto Pos = Text.find_first_of("_himnsuy");
+          Pos != StringRef::npos) {
         Text = Text.substr(0, Pos);
         Length = Pos;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150539.522054.patch
Type: text/x-patch
Size: 1490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230515/65e78059/attachment.bin>


More information about the cfe-commits mailing list