[llvm-branch-commits] [clang] 073506d - [clang-format] Insert a space between a numeric UDL and a dot

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 9 23:19:53 PST 2023


Author: Owen Pan
Date: 2023-02-10T08:19:40+01:00
New Revision: 073506d8c15ccd67307f2740015bbdcbb6e2f69f

URL: https://github.com/llvm/llvm-project/commit/073506d8c15ccd67307f2740015bbdcbb6e2f69f
DIFF: https://github.com/llvm/llvm-project/commit/073506d8c15ccd67307f2740015bbdcbb6e2f69f.diff

LOG: [clang-format] Insert a space between a numeric UDL and a dot

Fixes #60576.

Differential Revision: https://reviews.llvm.org/D143546

(cherry picked from commit b4e35c63711b4bde10b83607d04dab4bfdb86482)

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 49c30ca78debf..ca651eaa94406 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3833,6 +3833,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     return true;
 
   if (Style.isCpp()) {
+    // Space between UDL and dot: auto b = 4s .count();
+    if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+      return true;
     // Space between import <iostream>.
     // or import .....;
     if (Left.is(Keywords.kw_import) && Right.isOneOf(tok::less, tok::ellipsis))

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6530e2005e4c4..75da96a1b14cc 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25282,6 +25282,11 @@ TEST_F(FormatTest, InsertNewlineAtEOF) {
   verifyFormat("int i;\n", "int i;", Style);
 }
 
+TEST_F(FormatTest, SpaceAfterUDL) {
+  verifyFormat("auto c = (4s).count();");
+  verifyFormat("auto x = 5s .count() == 5;");
+}
+
 } // namespace
 } // namespace format
 } // namespace clang


        


More information about the llvm-branch-commits mailing list