Skip to content

Commit d821650

Browse files
authored
[clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (#81591)
Complete the switch from "AlwaysBreakAfterReturnType" to "BreakAfterReturnType".
1 parent de6fad5 commit d821650

File tree

8 files changed

+49
-54
lines changed

8 files changed

+49
-54
lines changed

clang/include/clang/Format/Format.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ struct FormatStyle {
10131013
/// This option is renamed to ``BreakAfterReturnType``.
10141014
/// \version 3.8
10151015
/// @deprecated
1016-
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
1016+
// ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
10171017

10181018
/// If ``true``, always break before multiline string literals.
10191019
///
@@ -1579,7 +1579,7 @@ struct FormatStyle {
15791579

15801580
/// The function declaration return type breaking style to use.
15811581
/// \version 19
1582-
// ReturnTypeBreakingStyle BreakAfterReturnType;
1582+
ReturnTypeBreakingStyle BreakAfterReturnType;
15831583

15841584
/// If ``true``, clang-format will always break after a Json array ``[``
15851585
/// otherwise it will scan until the closing ``]`` to determine if it should
@@ -4824,7 +4824,6 @@ struct FormatStyle {
48244824
R.AllowShortIfStatementsOnASingleLine &&
48254825
AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
48264826
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
4827-
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
48284827
AlwaysBreakBeforeMultilineStrings ==
48294828
R.AlwaysBreakBeforeMultilineStrings &&
48304829
AttributeMacros == R.AttributeMacros &&
@@ -4835,6 +4834,7 @@ struct FormatStyle {
48354834
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
48364835
BreakAfterAttributes == R.BreakAfterAttributes &&
48374836
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
4837+
BreakAfterReturnType == R.BreakAfterReturnType &&
48384838
BreakArrays == R.BreakArrays &&
48394839
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
48404840
BreakBeforeBraces == R.BreakBeforeBraces &&

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
329329
// Don't break after very short return types (e.g. "void") as that is often
330330
// unexpected.
331331
if (Current.is(TT_FunctionDeclarationName)) {
332-
if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None &&
332+
if (Style.BreakAfterReturnType == FormatStyle::RTBS_None &&
333333
State.Column < 6) {
334334
return false;
335335
}
336336

337-
if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
337+
if (Style.BreakAfterReturnType == FormatStyle::RTBS_ExceptShortType) {
338338
assert(State.Column >= State.FirstIndent);
339339
if (State.Column - State.FirstIndent < 6)
340340
return false;
@@ -597,7 +597,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
597597
!State.Line->ReturnTypeWrapped &&
598598
// Don't break before a C# function when no break after return type.
599599
(!Style.isCSharp() ||
600-
Style.AlwaysBreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
600+
Style.BreakAfterReturnType > FormatStyle::RTBS_ExceptShortType) &&
601601
// Don't always break between a JavaScript `function` and the function
602602
// name.
603603
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&

clang/lib/Format/Format.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,7 @@ template <> struct MappingTraits<FormatStyle> {
877877
if (!IO.outputting()) {
878878
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
879879
IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
880-
IO.mapOptional("AlwaysBreakAfterReturnType",
881-
Style.AlwaysBreakAfterReturnType);
880+
IO.mapOptional("AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
882881
IO.mapOptional("AlwaysBreakTemplateDeclarations",
883882
Style.BreakTemplateDeclarations);
884883
IO.mapOptional("BreakBeforeInheritanceComma",
@@ -957,7 +956,7 @@ template <> struct MappingTraits<FormatStyle> {
957956
IO.mapOptional("BreakAfterAttributes", Style.BreakAfterAttributes);
958957
IO.mapOptional("BreakAfterJavaFieldAnnotations",
959958
Style.BreakAfterJavaFieldAnnotations);
960-
IO.mapOptional("BreakAfterReturnType", Style.AlwaysBreakAfterReturnType);
959+
IO.mapOptional("BreakAfterReturnType", Style.BreakAfterReturnType);
961960
IO.mapOptional("BreakArrays", Style.BreakArrays);
962961
IO.mapOptional("BreakBeforeBinaryOperators",
963962
Style.BreakBeforeBinaryOperators);
@@ -1127,17 +1126,16 @@ template <> struct MappingTraits<FormatStyle> {
11271126
Style.WhitespaceSensitiveMacros);
11281127

11291128
// If AlwaysBreakAfterDefinitionReturnType was specified but
1130-
// AlwaysBreakAfterReturnType was not, initialize the latter from the
1131-
// former for backwards compatibility.
1129+
// BreakAfterReturnType was not, initialize the latter from the former for
1130+
// backwards compatibility.
11321131
if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
1133-
Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None) {
1132+
Style.BreakAfterReturnType == FormatStyle::RTBS_None) {
11341133
if (Style.AlwaysBreakAfterDefinitionReturnType ==
11351134
FormatStyle::DRTBS_All) {
1136-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
1135+
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
11371136
} else if (Style.AlwaysBreakAfterDefinitionReturnType ==
11381137
FormatStyle::DRTBS_TopLevel) {
1139-
Style.AlwaysBreakAfterReturnType =
1140-
FormatStyle::RTBS_TopLevelDefinitions;
1138+
Style.BreakAfterReturnType = FormatStyle::RTBS_TopLevelDefinitions;
11411139
}
11421140
}
11431141

@@ -1439,7 +1437,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14391437
LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
14401438
LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
14411439
LLVMStyle.AllowShortLoopsOnASingleLine = false;
1442-
LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
14431440
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
14441441
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
14451442
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
@@ -1469,6 +1466,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14691466
LLVMStyle.BreakAdjacentStringLiterals = true;
14701467
LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
14711468
LLVMStyle.BreakAfterJavaFieldAnnotations = false;
1469+
LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
14721470
LLVMStyle.BreakArrays = true;
14731471
LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
14741472
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
@@ -1822,12 +1820,12 @@ FormatStyle getMozillaStyle() {
18221820
FormatStyle MozillaStyle = getLLVMStyle();
18231821
MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false;
18241822
MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
1825-
MozillaStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevel;
18261823
MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
18271824
FormatStyle::DRTBS_TopLevel;
18281825
MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
18291826
MozillaStyle.BinPackParameters = false;
18301827
MozillaStyle.BinPackArguments = false;
1828+
MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
18311829
MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
18321830
MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
18331831
MozillaStyle.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
@@ -1871,7 +1869,7 @@ FormatStyle getWebKitStyle() {
18711869
FormatStyle getGNUStyle() {
18721870
FormatStyle Style = getLLVMStyle();
18731871
Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
1874-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
1872+
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
18751873
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
18761874
Style.BreakBeforeBraces = FormatStyle::BS_GNU;
18771875
Style.BreakBeforeTernaryOperators = true;
@@ -1908,7 +1906,7 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language) {
19081906
Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
19091907
Style.AllowShortLoopsOnASingleLine = false;
19101908
Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
1911-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
1909+
Style.BreakAfterReturnType = FormatStyle::RTBS_None;
19121910
return Style;
19131911
}
19141912

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,14 +3728,13 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
37283728
bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
37293729
assert(Line.MightBeFunctionDecl);
37303730

3731-
if ((Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_TopLevel ||
3732-
Style.AlwaysBreakAfterReturnType ==
3733-
FormatStyle::RTBS_TopLevelDefinitions) &&
3731+
if ((Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevel ||
3732+
Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevelDefinitions) &&
37343733
Line.Level > 0) {
37353734
return false;
37363735
}
37373736

3738-
switch (Style.AlwaysBreakAfterReturnType) {
3737+
switch (Style.BreakAfterReturnType) {
37393738
case FormatStyle::RTBS_None:
37403739
case FormatStyle::RTBS_Automatic:
37413740
case FormatStyle::RTBS_ExceptShortType:

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -677,38 +677,36 @@ TEST(ConfigParseTest, ParsesConfiguration) {
677677
" AfterControlStatement: false",
678678
BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Never);
679679

680-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
681-
CHECK_PARSE("BreakAfterReturnType: None", AlwaysBreakAfterReturnType,
680+
Style.BreakAfterReturnType = FormatStyle::RTBS_All;
681+
CHECK_PARSE("BreakAfterReturnType: None", BreakAfterReturnType,
682682
FormatStyle::RTBS_None);
683-
CHECK_PARSE("BreakAfterReturnType: Automatic", AlwaysBreakAfterReturnType,
683+
CHECK_PARSE("BreakAfterReturnType: Automatic", BreakAfterReturnType,
684684
FormatStyle::RTBS_Automatic);
685-
CHECK_PARSE("BreakAfterReturnType: ExceptShortType",
686-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
687-
CHECK_PARSE("BreakAfterReturnType: All", AlwaysBreakAfterReturnType,
685+
CHECK_PARSE("BreakAfterReturnType: ExceptShortType", BreakAfterReturnType,
686+
FormatStyle::RTBS_ExceptShortType);
687+
CHECK_PARSE("BreakAfterReturnType: All", BreakAfterReturnType,
688688
FormatStyle::RTBS_All);
689-
CHECK_PARSE("BreakAfterReturnType: TopLevel", AlwaysBreakAfterReturnType,
689+
CHECK_PARSE("BreakAfterReturnType: TopLevel", BreakAfterReturnType,
690690
FormatStyle::RTBS_TopLevel);
691-
CHECK_PARSE("BreakAfterReturnType: AllDefinitions",
692-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
693-
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions",
694-
AlwaysBreakAfterReturnType,
691+
CHECK_PARSE("BreakAfterReturnType: AllDefinitions", BreakAfterReturnType,
692+
FormatStyle::RTBS_AllDefinitions);
693+
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions", BreakAfterReturnType,
695694
FormatStyle::RTBS_TopLevelDefinitions);
696695
// For backward compatibility:
697-
CHECK_PARSE("AlwaysBreakAfterReturnType: None", AlwaysBreakAfterReturnType,
696+
CHECK_PARSE("AlwaysBreakAfterReturnType: None", BreakAfterReturnType,
698697
FormatStyle::RTBS_None);
699-
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic",
700-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_Automatic);
698+
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic", BreakAfterReturnType,
699+
FormatStyle::RTBS_Automatic);
701700
CHECK_PARSE("AlwaysBreakAfterReturnType: ExceptShortType",
702-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
703-
CHECK_PARSE("AlwaysBreakAfterReturnType: All", AlwaysBreakAfterReturnType,
701+
BreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
702+
CHECK_PARSE("AlwaysBreakAfterReturnType: All", BreakAfterReturnType,
704703
FormatStyle::RTBS_All);
705-
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevel",
706-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_TopLevel);
704+
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevel", BreakAfterReturnType,
705+
FormatStyle::RTBS_TopLevel);
707706
CHECK_PARSE("AlwaysBreakAfterReturnType: AllDefinitions",
708-
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
707+
BreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
709708
CHECK_PARSE("AlwaysBreakAfterReturnType: TopLevelDefinitions",
710-
AlwaysBreakAfterReturnType,
711-
FormatStyle::RTBS_TopLevelDefinitions);
709+
BreakAfterReturnType, FormatStyle::RTBS_TopLevelDefinitions);
712710

713711
Style.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
714712
CHECK_PARSE("BreakTemplateDeclarations: Leave", BreakTemplateDeclarations,

clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ TEST_F(DefinitionBlockSeparatorTest, Basic) {
144144
Style);
145145

146146
FormatStyle BreakAfterReturnTypeStyle = Style;
147-
BreakAfterReturnTypeStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
147+
BreakAfterReturnTypeStyle.BreakAfterReturnType = FormatStyle::RTBS_All;
148148
// Test uppercased long typename
149149
verifyFormat("class Foo {\n"
150150
" void\n"

clang/unittests/Format/FormatTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9870,7 +9870,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
98709870
Style.ColumnLimit = 60;
98719871

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

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

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

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

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

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

99729972
// All definitions should have the return type moved to its own line, but no
99739973
// kinds of declarations.
9974-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
9974+
Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
99759975
verifyFormat("class D {\n"
99769976
" int\n"
99779977
" f() {\n"
@@ -11939,7 +11939,7 @@ TEST_F(FormatTest, UnderstandsAttributes) {
1193911939
"aaaaaaaaaaaaaaaaaaaaaaa(int i);");
1194011940
verifyFormat("__attribute__((nodebug)) ::qualified_type f();");
1194111941
FormatStyle AfterType = getLLVMStyle();
11942-
AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
11942+
AfterType.BreakAfterReturnType = FormatStyle::RTBS_All;
1194311943
verifyFormat("__attribute__((nodebug)) void\n"
1194411944
"foo() {}",
1194511945
AfterType);

clang/unittests/Format/FormatTestCSharp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ TEST_F(FormatTestCSharp, CSharpNullForgiving) {
505505

506506
TEST_F(FormatTestCSharp, AttributesIndentation) {
507507
FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
508-
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
508+
Style.BreakAfterReturnType = FormatStyle::RTBS_None;
509509

510510
verifyFormat("[STAThread]\n"
511511
"static void Main(string[] args)\n"

0 commit comments

Comments
 (0)