[clang-format] Insert a space between a numeric UDL and a dot
authorOwen Pan <owenpiano@gmail.com>
Wed, 8 Feb 2023 02:36:28 +0000 (18:36 -0800)
committerOwen Pan <owenpiano@gmail.com>
Thu, 9 Feb 2023 21:34:57 +0000 (13:34 -0800)
Fixes #60576.

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

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

index 2186d68..2bafa48 100644 (file)
@@ -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))
index b00c597..69736ee 100644 (file)
@@ -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