This revision was automatically updated to reflect the committed changes. Closed by commit rGd9567babef30: Fix extraneous whitespace addition in line comments on clang-format directives (authored by penagos, committed by curdeius).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120188/new/ https://reviews.llvm.org/D120188 Files: clang/lib/Format/BreakableToken.cpp clang/unittests/Format/FormatTestComments.cpp Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -91,6 +91,11 @@ "// line 2\n" "void f() {}\n"); + EXPECT_EQ("// comment\n" + "// clang-format on\n", + format("//comment\n" + "// clang-format on\n")); + verifyFormat("void f() {\n" " // Doesn't do anything\n" "}"); Index: clang/lib/Format/BreakableToken.cpp =================================================================== --- clang/lib/Format/BreakableToken.cpp +++ clang/lib/Format/BreakableToken.cpp @@ -815,10 +815,13 @@ assert(Lines[i].size() > IndentPrefix.size()); const auto FirstNonSpace = Lines[i][IndentPrefix.size()]; - const auto AllowsSpaceChange = - SpacesInPrefix != 0 || - (!NoSpaceBeforeFirstCommentChar() || - (FirstNonSpace == '}' && FirstLineSpaceChange != 0)); + const bool IsFormatComment = LineTok && switchesFormatting(*LineTok); + const bool LineRequiresLeadingSpace = + !NoSpaceBeforeFirstCommentChar() || + (FirstNonSpace == '}' && FirstLineSpaceChange != 0); + const bool AllowsSpaceChange = + !IsFormatComment && + (SpacesInPrefix != 0 || LineRequiresLeadingSpace); if (PrefixSpaceChange[i] > 0 && AllowsSpaceChange) { Prefix[i] = IndentPrefix.str();
Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -91,6 +91,11 @@ "// line 2\n" "void f() {}\n"); + EXPECT_EQ("// comment\n" + "// clang-format on\n", + format("//comment\n" + "// clang-format on\n")); + verifyFormat("void f() {\n" " // Doesn't do anything\n" "}"); Index: clang/lib/Format/BreakableToken.cpp =================================================================== --- clang/lib/Format/BreakableToken.cpp +++ clang/lib/Format/BreakableToken.cpp @@ -815,10 +815,13 @@ assert(Lines[i].size() > IndentPrefix.size()); const auto FirstNonSpace = Lines[i][IndentPrefix.size()]; - const auto AllowsSpaceChange = - SpacesInPrefix != 0 || - (!NoSpaceBeforeFirstCommentChar() || - (FirstNonSpace == '}' && FirstLineSpaceChange != 0)); + const bool IsFormatComment = LineTok && switchesFormatting(*LineTok); + const bool LineRequiresLeadingSpace = + !NoSpaceBeforeFirstCommentChar() || + (FirstNonSpace == '}' && FirstLineSpaceChange != 0); + const bool AllowsSpaceChange = + !IsFormatComment && + (SpacesInPrefix != 0 || LineRequiresLeadingSpace); if (PrefixSpaceChange[i] > 0 && AllowsSpaceChange) { Prefix[i] = IndentPrefix.str();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits