Skip to content

[clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". #81591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 15, 2024
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
6 changes: 3 additions & 3 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ struct FormatStyle {
/// This option is renamed to ``BreakAfterReturnType``.
/// \version 3.8
/// @deprecated
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
// ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;

/// If ``true``, always break before multiline string literals.
///
Expand Down Expand Up @@ -1579,7 +1579,7 @@ struct FormatStyle {

/// The function declaration return type breaking style to use.
/// \version 19
// ReturnTypeBreakingStyle BreakAfterReturnType;
ReturnTypeBreakingStyle BreakAfterReturnType;

/// If ``true``, clang-format will always break after a Json array ``[``
/// otherwise it will scan until the closing ``]`` to determine if it should
Expand Down Expand Up @@ -4824,7 +4824,6 @@ struct FormatStyle {
R.AllowShortIfStatementsOnASingleLine &&
AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
Expand All @@ -4835,6 +4834,7 @@ struct FormatStyle {
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
BreakAfterAttributes == R.BreakAfterAttributes &&
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
BreakAfterReturnType == R.BreakAfterReturnType &&
BreakArrays == R.BreakArrays &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
BreakBeforeBraces == R.BreakBeforeBraces &&
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
// Don't break after very short return types (e.g. "void") as that is often
// unexpected.
if (Current.is(TT_FunctionDeclarationName)) {
if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None &&
if (Style.BreakAfterReturnType == FormatStyle::RTBS_None &&
State.Column < 6) {
return false;
}

if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
if (Style.BreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
assert(State.Column >= State.FirstIndent);
if (State.Column - State.FirstIndent < 6)
return false;
Expand Down Expand Up @@ -597,7 +597,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
!State.Line->ReturnTypeWrapped &&
// Don't break before a C# function when no break after return type.
(!Style.isCSharp() ||
Style.AlwaysBreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
Style.BreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
// Don't always break between a JavaScript `function` and the function
// name.
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
Expand Down
24 changes: 11 additions & 13 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ template <> struct MappingTraits<FormatStyle> {
if (!IO.outputting()) {
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
IO.mapOptional("AlwaysBreakAfterReturnType",
Style.AlwaysBreakAfterReturnType);
IO.mapOptional("AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.BreakTemplateDeclarations);
IO.mapOptional("BreakBeforeInheritanceComma",
Expand Down Expand Up @@ -957,7 +956,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("BreakAfterAttributes", Style.BreakAfterAttributes);
IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
IO.mapOptional("BreakAfterReturnType", Style.AlwaysBreakAfterReturnType);
IO.mapOptional("BreakAfterReturnType", Style.BreakAfterReturnType);
IO.mapOptional("BreakArrays", Style.BreakArrays);
IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
Expand Down Expand Up @@ -1127,17 +1126,16 @@ template <> struct MappingTraits<FormatStyle> {
Style.WhitespaceSensitiveMacros);

// If AlwaysBreakAfterDefinitionReturnType was specified but
// AlwaysBreakAfterReturnType was not, initialize the latter from the
// former for backwards compatibility.
// BreakAfterReturnType was not, initialize the latter from the former for
// backwards compatibility.
if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None) {
Style.BreakAfterReturnType == FormatStyle::RTBS_None) {
if (Style.AlwaysBreakAfterDefinitionReturnType ==
FormatStyle::DRTBS_All) {
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
} else if (Style.AlwaysBreakAfterDefinitionReturnType ==
FormatStyle::DRTBS_TopLevel) {
Style.AlwaysBreakAfterReturnType =
FormatStyle::RTBS_TopLevelDefinitions;
Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
}
}

Expand Down Expand Up @@ -1439,7 +1437,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
LLVMStyle.AllowShortLoopsOnASingleLine = false;
LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
Expand Down Expand Up @@ -1469,6 +1466,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BreakAdjacentStringLiterals = true;
LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
LLVMStyle.BreakAfterJavaFieldAnnotations = false;
LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
LLVMStyle.BreakArrays = true;
LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
Expand Down Expand Up @@ -1822,12 +1820,12 @@ FormatStyle getMozillaStyle() {
FormatStyle MozillaStyle = getLLVMStyle();
MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false;
MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
MozillaStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevel;
MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
FormatStyle::DRTBS_TopLevel;
MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
MozillaStyle.BinPackParameters = false;
MozillaStyle.BinPackArguments = false;
MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
MozillaStyle.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
Expand Down Expand Up @@ -1871,7 +1869,7 @@ FormatStyle getWebKitStyle() {
FormatStyle getGNUStyle() {
FormatStyle Style = getLLVMStyle();
Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
Style.BreakBeforeBraces = FormatStyle::BS_GNU;
Style.BreakBeforeTernaryOperators = true;
Expand Down Expand Up @@ -1908,7 +1906,7 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language) {
Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
Style.AllowShortLoopsOnASingleLine = false;
Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
Style.BreakAfterReturnType = FormatStyle::RTBS_None;
return Style;
}

Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3726,14 +3726,13 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
assert(Line.MightBeFunctionDecl);

if ((Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_TopLevel ||
Style.AlwaysBreakAfterReturnType ==
FormatStyle::RTBS_TopLevelDefinitions) &&
if ((Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevel ||
Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevelDefinitions) &&
Line.Level > 0) {
return false;
}

switch (Style.AlwaysBreakAfterReturnType) {
switch (Style.BreakAfterReturnType) {
case FormatStyle::RTBS_None:
case FormatStyle::RTBS_Automatic:
case FormatStyle::RTBS_ExceptShortType:
Expand Down
40 changes: 19 additions & 21 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,38 +677,36 @@ TEST(ConfigParseTest, ParsesConfiguration) {
" AfterControlStatement: false",
BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Never);

Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
CHECK_PARSE("BreakAfterReturnType: None", AlwaysBreakAfterReturnType,
Style.BreakAfterReturnType = FormatStyle::RTBS_All;
CHECK_PARSE("BreakAfterReturnType: None", BreakAfterReturnType,
FormatStyle::RTBS_None);
CHECK_PARSE("BreakAfterReturnType: Automatic", AlwaysBreakAfterReturnType,
CHECK_PARSE("BreakAfterReturnType: Automatic", BreakAfterReturnType,
FormatStyle::RTBS_Automatic);
CHECK_PARSE("BreakAfterReturnType: ExceptShortType",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
CHECK_PARSE("BreakAfterReturnType: All", AlwaysBreakAfterReturnType,
CHECK_PARSE("BreakAfterReturnType: ExceptShortType", BreakAfterReturnType,
FormatStyle::RTBS_ExceptShortType);
CHECK_PARSE("BreakAfterReturnType: All", BreakAfterReturnType,
FormatStyle::RTBS_All);
CHECK_PARSE("BreakAfterReturnType: TopLevel", AlwaysBreakAfterReturnType,
CHECK_PARSE("BreakAfterReturnType: TopLevel", BreakAfterReturnType,
FormatStyle::RTBS_TopLevel);
CHECK_PARSE("BreakAfterReturnType: AllDefinitions",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions",
AlwaysBreakAfterReturnType,
CHECK_PARSE("BreakAfterReturnType: AllDefinitions", BreakAfterReturnType,
FormatStyle::RTBS_AllDefinitions);
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions", BreakAfterReturnType,
FormatStyle::RTBS_TopLevelDefinitions);
// For backward compatibility:
CHECK_PARSE("AlwaysBreakAfterReturnType: None", AlwaysBreakAfterReturnType,
CHECK_PARSE("AlwaysBreakAfterReturnType: None", BreakAfterReturnType,
FormatStyle::RTBS_None);
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_Automatic);
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic", BreakAfterReturnType,
FormatStyle::RTBS_Automatic);
CHECK_PARSE("AlwaysBreakAfterReturnType: ExceptShortType",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
CHECK_PARSE("AlwaysBreakAfterReturnType: All", AlwaysBreakAfterReturnType,
BreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
CHECK_PARSE("AlwaysBreakAfterReturnType: All", BreakAfterReturnType,
FormatStyle::RTBS_All);
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevel",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_TopLevel);
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevel", BreakAfterReturnType,
FormatStyle::RTBS_TopLevel);
CHECK_PARSE("AlwaysBreakAfterReturnType: AllDefinitions",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
BreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevelDefinitions",
AlwaysBreakAfterReturnType,
FormatStyle::RTBS_TopLevelDefinitions);
BreakAfterReturnType, FormatStyle::RTBS_TopLevelDefinitions);

Style.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
CHECK_PARSE("BreakTemplateDeclarations: Leave", BreakTemplateDeclarations,
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEST_F(DefinitionBlockSeparatorTest, Basic) {
Style);

FormatStyle BreakAfterReturnTypeStyle = Style;
BreakAfterReturnTypeStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
BreakAfterReturnTypeStyle.BreakAfterReturnType = FormatStyle::RTBS_All;
// Test uppercased long typename
verifyFormat("class Foo {\n"
" void\n"
Expand Down
16 changes: 8 additions & 8 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9870,7 +9870,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
Style.ColumnLimit = 60;

// No declarations or definitions should be moved to own line.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
Style.BreakAfterReturnType = FormatStyle::RTBS_None;
verifyFormat("class A {\n"
" int f() { return 1; }\n"
" int g();\n"
Expand All @@ -9884,7 +9884,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
Style);

// It is now allowed to break after a short return type if necessary.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_Automatic;
Style.BreakAfterReturnType = FormatStyle::RTBS_Automatic;
verifyFormat("class A {\n"
" int f() { return 1; }\n"
" int g();\n"
Expand All @@ -9898,7 +9898,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
Style);

// It now must never break after a short return type.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_ExceptShortType;
Style.BreakAfterReturnType = FormatStyle::RTBS_ExceptShortType;
verifyFormat("class A {\n"
" int f() { return 1; }\n"
" int g();\n"
Expand All @@ -9913,7 +9913,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {

// All declarations and definitions should have the return type moved to its
// own line.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
Style.BreakAfterReturnType = FormatStyle::RTBS_All;
Style.TypenameMacros = {"LIST"};
verifyFormat("SomeType\n"
"funcdecl(LIST(uint64_t));",
Expand All @@ -9940,7 +9940,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {

// Top-level definitions, and no kinds of declarations should have the
// return type moved to its own line.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
verifyFormat("class B {\n"
" int f() { return 1; }\n"
" int g();\n"
Expand All @@ -9954,7 +9954,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {

// Top-level definitions and declarations should have the return type moved
// to its own line.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevel;
Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
verifyFormat("class C {\n"
" int f() { return 1; }\n"
" int g();\n"
Expand All @@ -9971,7 +9971,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {

// All definitions should have the return type moved to its own line, but no
// kinds of declarations.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
verifyFormat("class D {\n"
" int\n"
" f() {\n"
Expand Down Expand Up @@ -11939,7 +11939,7 @@ TEST_F(FormatTest, UnderstandsAttributes) {
"aaaaaaaaaaaaaaaaaaaaaaa(int i);");
verifyFormat("__attribute__((nodebug)) ::qualified_type f();");
FormatStyle AfterType = getLLVMStyle();
AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
AfterType.BreakAfterReturnType = FormatStyle::RTBS_All;
verifyFormat("__attribute__((nodebug)) void\n"
"foo() {}",
AfterType);
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTestCSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ TEST_F(FormatTestCSharp, CSharpNullForgiving) {

TEST_F(FormatTestCSharp, AttributesIndentation) {
FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
Style.BreakAfterReturnType = FormatStyle::RTBS_None;

verifyFormat("[STAThread]\n"
"static void Main(string[] args)\n"
Expand Down