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 . // 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