Skip to content

Commit

Permalink
[clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations"
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca committed Feb 10, 2024
1 parent c5cbfc5 commit 7664ddf
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 40 deletions.
7 changes: 3 additions & 4 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ struct FormatStyle {
/// This option is renamed to ``BreakTemplateDeclarations``.
/// \version 3.4
/// @deprecated
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
// BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;

/// A vector of strings that should be interpreted as attributes/qualifiers
/// instead of identifiers. This can be useful for language extensions or
Expand Down Expand Up @@ -2296,7 +2296,7 @@ struct FormatStyle {

/// The template declaration breaking style to use.
/// \version 19
// BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
BreakTemplateDeclarationsStyle BreakTemplateDeclarations;

/// If ``true``, consecutive namespace declarations will be on the same
/// line. If ``false``, each namespace is declared on a new line.
Expand Down Expand Up @@ -4822,8 +4822,7 @@ struct FormatStyle {
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AlwaysBreakTemplateDeclarations ==
R.AlwaysBreakTemplateDeclarations &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&

This comment has been minimized.

Copy link
@HazardyKnusperkeks

HazardyKnusperkeks Feb 10, 2024

Contributor

Now this isn't sorted anymore. ;)

This comment has been minimized.

Copy link
@owenca

owenca Feb 10, 2024

Author Contributor

You're right!

This comment has been minimized.

Copy link
@owenca

owenca Feb 11, 2024

Author Contributor

Fixed in 5aec939.

AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}
}
return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
(Style.AlwaysBreakTemplateDeclarations !=
FormatStyle::BTDS_Leave ||
return Style.BreakTemplateDeclarations != FormatStyle::BTDS_No &&
(Style.BreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
Current.NewlinesBefore > 0);
}
if (Previous.is(TT_FunctionAnnotationRParen) &&
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
Style.BreakTemplateDeclarations);

This comment has been minimized.

Copy link
@HazardyKnusperkeks

HazardyKnusperkeks Feb 10, 2024

Contributor

We handled this differently for deprecation in the past, didn't we?

We should only use this value if it is set and BreakTemplateDeclarations isn't.

This comment has been minimized.

Copy link
@owenca

owenca Feb 10, 2024

Author Contributor

AlwaysBreakTemplateDeclarations is renamed to BreakTemplateDeclarations, but its type remains unchanged. So we can simply map it to Style.BreakTemplateDeclarations for backward compatibility. Am I right?

This comment has been minimized.

Copy link
@HazardyKnusperkeks

HazardyKnusperkeks Feb 11, 2024

Contributor

Forget what I said, I thought we were at a different location, did not have enough context.
Everything is correct.

IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
Expand Down Expand Up @@ -972,7 +972,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
IO.mapOptional("BreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
Style.BreakTemplateDeclarations);
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
IO.mapOptional("CompactNamespaces", Style.CompactNamespaces);
Expand Down Expand Up @@ -1441,7 +1441,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
LLVMStyle.AttributeMacros.push_back("__capability");
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BinPackArguments = true;
Expand Down Expand Up @@ -1631,7 +1631,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
FormatStyle::SIS_WithoutElse;
GoogleStyle.AllowShortLoopsOnASingleLine = true;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
GoogleStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
GoogleStyle.DerivePointerAlignment = true;
GoogleStyle.IncludeStyle.IncludeCategories = {{"^<ext/.*\\.h>", 2, 0, false},
{"^<.*\\.h>", 1, 0, false},
Expand Down Expand Up @@ -1824,7 +1824,7 @@ FormatStyle getMozillaStyle() {
MozillaStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevel;
MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
FormatStyle::DRTBS_TopLevel;
MozillaStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
MozillaStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
MozillaStyle.BinPackParameters = false;
MozillaStyle.BinPackArguments = false;
MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5184,8 +5184,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
// concept ...
if (Right.is(tok::kw_concept))
return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
(Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
return Style.BreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
(Style.BreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
Right.NewlinesBefore > 0);
}
if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
Expand Down Expand Up @@ -5620,7 +5620,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
if (Right.is(TT_RequiresClause))
return true;
if (Left.ClosesTemplateDeclaration) {
return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
return Style.BreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
Right.NewlinesBefore > 0;
}
if (Left.is(TT_FunctionAnnotationRParen))
Expand Down
38 changes: 19 additions & 19 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,32 +694,32 @@ TEST(ConfigParseTest, ParsesConfiguration) {
AlwaysBreakAfterReturnType,
FormatStyle::RTBS_TopLevelDefinitions);

Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
CHECK_PARSE("BreakTemplateDeclarations: Leave",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
CHECK_PARSE("BreakTemplateDeclarations: No", AlwaysBreakTemplateDeclarations,
Style.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
CHECK_PARSE("BreakTemplateDeclarations: Leave", BreakTemplateDeclarations,
FormatStyle::BTDS_Leave);
CHECK_PARSE("BreakTemplateDeclarations: No", BreakTemplateDeclarations,
FormatStyle::BTDS_No);
CHECK_PARSE("BreakTemplateDeclarations: MultiLine",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: Yes", AlwaysBreakTemplateDeclarations,
CHECK_PARSE("BreakTemplateDeclarations: MultiLine", BreakTemplateDeclarations,
FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: Yes", BreakTemplateDeclarations,
FormatStyle::BTDS_Yes);
CHECK_PARSE("BreakTemplateDeclarations: false", BreakTemplateDeclarations,
FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: true", BreakTemplateDeclarations,
FormatStyle::BTDS_Yes);
CHECK_PARSE("BreakTemplateDeclarations: false",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: true",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Yes);
// For backward compatibility:
CHECK_PARSE("AlwaysBreakTemplateDeclarations: Leave",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: No",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_No);
BreakTemplateDeclarations, FormatStyle::BTDS_Leave);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: No", BreakTemplateDeclarations,
FormatStyle::BTDS_No);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: MultiLine",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: Yes",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Yes);
BreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: Yes", BreakTemplateDeclarations,
FormatStyle::BTDS_Yes);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: false",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
BreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: true",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Yes);
BreakTemplateDeclarations, FormatStyle::BTDS_Yes);

Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: None",
Expand Down
11 changes: 5 additions & 6 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10638,7 +10638,7 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
" const typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);");

FormatStyle AlwaysBreak = getLLVMStyle();
AlwaysBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
AlwaysBreak.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
verifyFormat("template <typename T>\nclass C {};", AlwaysBreak);
verifyFormat("template <typename T>\nvoid f();", AlwaysBreak);
verifyFormat("template <typename T>\nvoid f() {}", AlwaysBreak);
Expand Down Expand Up @@ -10667,7 +10667,7 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
"};");

FormatStyle NeverBreak = getLLVMStyle();
NeverBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_No;
NeverBreak.BreakTemplateDeclarations = FormatStyle::BTDS_No;
verifyFormat("template <typename T> class C {};", NeverBreak);
verifyFormat("template <typename T> void f();", NeverBreak);
verifyFormat("template <typename T> void f() {}", NeverBreak);
Expand Down Expand Up @@ -10699,7 +10699,7 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
NeverBreak);

auto Style = getLLVMStyle();
Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Leave;
Style.BreakTemplateDeclarations = FormatStyle::BTDS_Leave;

verifyNoChange("template <typename T>\n"
"class C {};",
Expand Down Expand Up @@ -11297,7 +11297,7 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("SomeType MemberFunction( const Deleted & ) &;", Spaces);

FormatStyle BreakTemplate = getLLVMStyle();
BreakTemplate.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
BreakTemplate.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;

verifyFormat("struct f {\n"
" template <class T>\n"
Expand Down Expand Up @@ -11330,8 +11330,7 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
BreakTemplate);

FormatStyle AlignLeftBreakTemplate = getLLVMStyle();
AlignLeftBreakTemplate.AlwaysBreakTemplateDeclarations =
FormatStyle::BTDS_Yes;
AlignLeftBreakTemplate.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
AlignLeftBreakTemplate.PointerAlignment = FormatStyle::PAS_Left;

verifyFormat("struct f {\n"
Expand Down

0 comments on commit 7664ddf

Please sign in to comment.