Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
// name.
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
CurrentState.BreakBeforeParameter) {
for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous)
if (Tok->FirstAfterPPDirectiveLine || Tok->is(TT_LineComment))
return false;

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ struct FormatToken {
/// Has "\n\f\n" or "\n\f\r\n" before TokenText.
bool HasFormFeedBefore = false;

/// Is the first token after a PPDirective line.
bool FirstAfterPPDirectiveLine = false;

/// Number of optional braces to be inserted after this token:
/// -1: a single left brace
/// 0: no braces
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5091,8 +5091,10 @@ UnwrappedLineParser::parseMacroCall() {
void UnwrappedLineParser::pushToken(FormatToken *Tok) {
Line->Tokens.push_back(UnwrappedLineNode(Tok));
if (MustBreakBeforeNextToken) {
Line->Tokens.back().Tok->MustBreakBefore = true;
Line->Tokens.back().Tok->MustBreakBeforeFinalized = true;
auto &Tok = *Line->Tokens.back().Tok;
Tok.MustBreakBefore = true;
Tok.MustBreakBeforeFinalized = true;
Tok.FirstAfterPPDirectiveLine = true;
MustBreakBeforeNextToken = false;
}
}
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6832,6 +6832,11 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {
" param3) {\n"
" f();\n"
"}");

verifyFormat("#ifdef __cplusplus\n"
"extern \"C\"\n"
"#endif\n"
" void f();");
}

TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
Expand Down Expand Up @@ -8539,6 +8544,7 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
verifyGoogleFormat(
"SomeLoooooooooooooooooooooooooooooogType operator<<(\n"
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");

verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1);");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaa\n"
Expand All @@ -8552,6 +8558,9 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
"aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);");

verifyFormat("extern \"C\" //\n"
" void f();");

FormatStyle Style = getLLVMStyle();
Style.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
Expand Down