Skip to content

Commit

Permalink
[clang-format] Insert a space between a numeric UDL and a dot
Browse files Browse the repository at this point in the history
Fixes #60576.

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

(cherry picked from commit b4e35c6)
  • Loading branch information
owenca authored and tru committed Feb 10, 2023
1 parent d956ed0 commit 073506d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 073506d

Please sign in to comment.