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

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 9 13:35:08 PST 2023


Author: Owen Pan
Date: 2023-02-09T13:34:57-08:00
New Revision: b4e35c63711b4bde10b83607d04dab4bfdb86482

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

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

Fixes #60576.

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

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 2186d68ab430b..2bafa48b53363 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3893,6 +3893,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 b00c597b69a1d..69736ee497930 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25407,6 +25407,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 cfe-commits mailing list