Skip to content

Commit 8cd2b43

Browse files
committed
merge main into amd-staging
2 parents 10869ad + 12769aa commit 8cd2b43

File tree

51 files changed

+1403
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1403
-150
lines changed

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ Diagnostics which have a corresponding warning option, are named
111111
``-Wliteral-conversion`` will be reported with check name
112112
``clang-diagnostic-literal-conversion``.
113113

114+
Clang compiler errors (such as syntax errors, semantic errors, or other failures
115+
that prevent Clang from compiling the code) are reported with the check name
116+
``clang-diagnostic-error``. These represent fundamental compilation failures that
117+
must be fixed before :program:`clang-tidy` can perform its analysis. Unlike other
118+
diagnostics, ``clang-diagnostic-error`` cannot be disabled, as :program:`clang-tidy`
119+
requires valid code to function.
120+
114121
The ``-fix`` flag instructs :program:`clang-tidy` to fix found errors if
115122
supported by corresponding checks.
116123

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,13 +6486,51 @@ the configuration (without a prefix: ``Auto``).
64866486
.. _SpaceInEmptyBlock:
64876487

64886488
**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`<SpaceInEmptyBlock>`
6489-
If ``true``, spaces will be inserted into ``{}``.
6489+
This option is **deprecated**. See ``Block`` of ``SpaceInEmptyBraces``.
6490+
6491+
.. _SpaceInEmptyBraces:
6492+
6493+
**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) :versionbadge:`clang-format 22` :ref:`<SpaceInEmptyBraces>`
6494+
Specifies when to insert a space in empty braces.
6495+
6496+
.. note::
6497+
6498+
This option doesn't apply to initializer braces if
6499+
``Cpp11BracedListStyle`` is set to ``true``.
6500+
6501+
Possible values:
6502+
6503+
* ``SIEB_Always`` (in configuration: ``Always``)
6504+
Always insert a space in empty braces.
6505+
6506+
.. code-block:: c++
6507+
6508+
void f() { }
6509+
class Unit { };
6510+
auto a = [] { };
6511+
int x{ };
6512+
6513+
* ``SIEB_Block`` (in configuration: ``Block``)
6514+
Only insert a space in empty blocks.
6515+
6516+
.. code-block:: c++
6517+
6518+
void f() { }
6519+
class Unit { };
6520+
auto a = [] { };
6521+
int x{};
6522+
6523+
* ``SIEB_Never`` (in configuration: ``Never``)
6524+
Never insert a space in empty braces.
6525+
6526+
.. code-block:: c++
6527+
6528+
void f() {}
6529+
class Unit {};
6530+
auto a = [] {};
6531+
int x{};
64906532

6491-
.. code-block:: c++
64926533

6493-
true: false:
6494-
void f() { } vs. void f() {}
6495-
while (true) { } while (true) {}
64966534

64976535
.. _SpaceInEmptyParentheses:
64986536

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ AST Matchers
566566

567567
clang-format
568568
------------
569+
- Add ``SpaceInEmptyBraces`` option and set it to ``Always`` for WebKit style.
569570

570571
libclang
571572
--------

clang/include/clang/Format/Format.h

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4813,14 +4813,45 @@ struct FormatStyle {
48134813
/// \version 7
48144814
bool SpaceBeforeRangeBasedForLoopColon;
48154815

4816-
/// If ``true``, spaces will be inserted into ``{}``.
4817-
/// \code
4818-
/// true: false:
4819-
/// void f() { } vs. void f() {}
4820-
/// while (true) { } while (true) {}
4821-
/// \endcode
4816+
/// This option is **deprecated**. See ``Block`` of ``SpaceInEmptyBraces``.
48224817
/// \version 10
4823-
bool SpaceInEmptyBlock;
4818+
// bool SpaceInEmptyBlock;
4819+
4820+
/// Style of when to insert a space in empty braces.
4821+
enum SpaceInEmptyBracesStyle : int8_t {
4822+
/// Always insert a space in empty braces.
4823+
/// \code
4824+
/// void f() { }
4825+
/// class Unit { };
4826+
/// auto a = [] { };
4827+
/// int x{ };
4828+
/// \endcode
4829+
SIEB_Always,
4830+
/// Only insert a space in empty blocks.
4831+
/// \code
4832+
/// void f() { }
4833+
/// class Unit { };
4834+
/// auto a = [] { };
4835+
/// int x{};
4836+
/// \endcode
4837+
SIEB_Block,
4838+
/// Never insert a space in empty braces.
4839+
/// \code
4840+
/// void f() {}
4841+
/// class Unit {};
4842+
/// auto a = [] {};
4843+
/// int x{};
4844+
/// \endcode
4845+
SIEB_Never
4846+
};
4847+
4848+
/// Specifies when to insert a space in empty braces.
4849+
/// \note
4850+
/// This option doesn't apply to initializer braces if
4851+
/// ``Cpp11BracedListStyle`` is set to ``true``.
4852+
/// \endnote
4853+
/// \version 22
4854+
SpaceInEmptyBracesStyle SpaceInEmptyBraces;
48244855

48254856
/// If ``true``, spaces may be inserted into ``()``.
48264857
/// This option is **deprecated**. See ``InEmptyParentheses`` of
@@ -5494,7 +5525,7 @@ struct FormatStyle {
54945525
SpaceBeforeRangeBasedForLoopColon ==
54955526
R.SpaceBeforeRangeBasedForLoopColon &&
54965527
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
5497-
SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
5528+
SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
54985529
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
54995530
SpacesInAngles == R.SpacesInAngles &&
55005531
SpacesInContainerLiterals == R.SpacesInContainerLiterals &&

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,16 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
629629
// name.
630630
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
631631
CurrentState.BreakBeforeParameter) {
632-
for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous)
633-
if (Tok->FirstAfterPPLine || Tok->is(TT_LineComment))
632+
for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous) {
633+
if (Tok->is(TT_LineComment))
634634
return false;
635+
if (Tok->is(TT_TemplateCloser)) {
636+
Tok = Tok->MatchingParen;
637+
assert(Tok);
638+
}
639+
if (Tok->FirstAfterPPLine)
640+
return false;
641+
}
635642

636643
return true;
637644
}

clang/lib/Format/Format.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,15 @@ struct ScalarEnumerationTraits<FormatStyle::SpaceBeforeParensStyle> {
763763
}
764764
};
765765

766+
template <>
767+
struct ScalarEnumerationTraits<FormatStyle::SpaceInEmptyBracesStyle> {
768+
static void enumeration(IO &IO, FormatStyle::SpaceInEmptyBracesStyle &Value) {
769+
IO.enumCase(Value, "Always", FormatStyle::SIEB_Always);
770+
IO.enumCase(Value, "Block", FormatStyle::SIEB_Block);
771+
IO.enumCase(Value, "Never", FormatStyle::SIEB_Never);
772+
}
773+
};
774+
766775
template <> struct ScalarEnumerationTraits<FormatStyle::SpacesInAnglesStyle> {
767776
static void enumeration(IO &IO, FormatStyle::SpacesInAnglesStyle &Value) {
768777
IO.enumCase(Value, "Never", FormatStyle::SIAS_Never);
@@ -931,6 +940,7 @@ template <> struct MappingTraits<FormatStyle> {
931940
bool DeriveLineEnding = true;
932941
bool UseCRLF = false;
933942

943+
bool SpaceInEmptyBlock = false;
934944
bool SpaceInEmptyParentheses = false;
935945
bool SpacesInConditionalStatement = false;
936946
bool SpacesInCStyleCastParentheses = false;
@@ -960,6 +970,7 @@ template <> struct MappingTraits<FormatStyle> {
960970
IO.mapOptional("PointerBindsToType", Style.PointerAlignment);
961971
IO.mapOptional("SpaceAfterControlStatementKeyword",
962972
Style.SpaceBeforeParens);
973+
IO.mapOptional("SpaceInEmptyBlock", SpaceInEmptyBlock);
963974
IO.mapOptional("SpaceInEmptyParentheses", SpaceInEmptyParentheses);
964975
IO.mapOptional("SpacesInConditionalStatement",
965976
SpacesInConditionalStatement);
@@ -1193,7 +1204,7 @@ template <> struct MappingTraits<FormatStyle> {
11931204
Style.SpaceBeforeRangeBasedForLoopColon);
11941205
IO.mapOptional("SpaceBeforeSquareBrackets",
11951206
Style.SpaceBeforeSquareBrackets);
1196-
IO.mapOptional("SpaceInEmptyBlock", Style.SpaceInEmptyBlock);
1207+
IO.mapOptional("SpaceInEmptyBraces", Style.SpaceInEmptyBraces);
11971208
IO.mapOptional("SpacesBeforeTrailingComments",
11981209
Style.SpacesBeforeTrailingComments);
11991210
IO.mapOptional("SpacesInAngles", Style.SpacesInAngles);
@@ -1276,6 +1287,13 @@ template <> struct MappingTraits<FormatStyle> {
12761287
Style.LineEnding = FormatStyle::LE_DeriveCRLF;
12771288
}
12781289

1290+
// If SpaceInEmptyBlock was specified but SpaceInEmptyBraces was not,
1291+
// initialize the latter from the former for backward compatibility.
1292+
if (SpaceInEmptyBlock &&
1293+
Style.SpaceInEmptyBraces == FormatStyle::SIEB_Never) {
1294+
Style.SpaceInEmptyBraces = FormatStyle::SIEB_Block;
1295+
}
1296+
12791297
if (Style.SpacesInParens != FormatStyle::SIPO_Custom &&
12801298
(SpacesInParentheses || SpaceInEmptyParentheses ||
12811299
SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
@@ -1677,7 +1695,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16771695
LLVMStyle.SpaceBeforeParensOptions.AfterIfMacros = true;
16781696
LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
16791697
LLVMStyle.SpaceBeforeSquareBrackets = false;
1680-
LLVMStyle.SpaceInEmptyBlock = false;
1698+
LLVMStyle.SpaceInEmptyBraces = FormatStyle::SIEB_Never;
16811699
LLVMStyle.SpacesBeforeTrailingComments = 1;
16821700
LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
16831701
LLVMStyle.SpacesInContainerLiterals = true;
@@ -1984,7 +2002,7 @@ FormatStyle getWebKitStyle() {
19842002
Style.ObjCSpaceAfterProperty = true;
19852003
Style.PointerAlignment = FormatStyle::PAS_Left;
19862004
Style.SpaceBeforeCpp11BracedList = true;
1987-
Style.SpaceInEmptyBlock = true;
2005+
Style.SpaceInEmptyBraces = FormatStyle::SIEB_Always;
19882006
return Style;
19892007
}
19902008

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,9 @@ class AnnotatingParser {
25902590
if (!Tok.Previous || Tok.isNot(tok::identifier) || Tok.is(TT_ClassHeadName))
25912591
return false;
25922592

2593+
if (Tok.endsSequence(Keywords.kw_final, TT_ClassHeadName))
2594+
return false;
2595+
25932596
if ((Style.isJavaScript() || Style.isJava()) && Tok.is(Keywords.kw_extends))
25942597
return false;
25952598

@@ -4513,16 +4516,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
45134516
return Left.is(tok::hash);
45144517
if (Left.isOneOf(tok::hashhash, tok::hash))
45154518
return Right.is(tok::hash);
4516-
if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
4517-
Right.MatchingParen == &Left && Line.Children.empty()) {
4518-
return Style.SpaceInEmptyBlock;
4519-
}
45204519
if (Style.SpacesInParens == FormatStyle::SIPO_Custom) {
4521-
if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
4522-
(Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
4523-
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
4520+
if (Left.is(tok::l_paren) && Right.is(tok::r_paren))
45244521
return Style.SpacesInParensOptions.InEmptyParentheses;
4525-
}
45264522
if (Style.SpacesInParensOptions.ExceptDoubleParentheses &&
45274523
Left.is(tok::r_paren) && Right.is(tok::r_paren)) {
45284524
auto *InnerLParen = Left.MatchingParen;
@@ -4800,8 +4796,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48004796
Right.is(TT_ArraySubscriptLSquare))) {
48014797
return false;
48024798
}
4803-
if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
4804-
return !Left.Children.empty(); // No spaces in "{}".
48054799
if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
48064800
(Right.is(tok::r_brace) && Right.MatchingParen &&
48074801
Right.MatchingParen->isNot(BK_Block))) {
@@ -4983,6 +4977,17 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
49834977
if (Left.is(tok::star) && Right.is(tok::comment))
49844978
return true;
49854979

4980+
if (Left.is(tok::l_brace) && Right.is(tok::r_brace) &&
4981+
Left.Children.empty()) {
4982+
if (Left.is(BK_Block))
4983+
return Style.SpaceInEmptyBraces != FormatStyle::SIEB_Never;
4984+
if (Style.Cpp11BracedListStyle) {
4985+
return Style.SpacesInParens == FormatStyle::SIPO_Custom &&
4986+
Style.SpacesInParensOptions.InEmptyParentheses;
4987+
}
4988+
return Style.SpaceInEmptyBraces == FormatStyle::SIEB_Always;
4989+
}
4990+
49864991
const auto *BeforeLeft = Left.Previous;
49874992

49884993
if (IsCpp) {
@@ -6269,7 +6274,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62696274
}
62706275

62716276
if (Right.is(tok::colon) &&
6272-
!Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon)) {
6277+
!Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon,
6278+
TT_BitFieldColon)) {
62736279
return false;
62746280
}
62756281
if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,8 @@ class LineJoiner {
864864
if (ShouldMerge()) {
865865
// We merge empty blocks even if the line exceeds the column limit.
866866
Tok->SpacesRequiredBefore =
867-
(Style.SpaceInEmptyBlock || Line.Last->is(tok::comment)) ? 1 : 0;
867+
Style.SpaceInEmptyBraces != FormatStyle::SIEB_Never ||
868+
Line.Last->is(tok::comment);
868869
Tok->CanBreakBefore = true;
869870
return 1;
870871
} else if (Limit != 0 && !Line.startsWithNamespace() &&

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
200200
CHECK_PARSE_BOOL(RemoveSemicolon);
201201
CHECK_PARSE_BOOL(SkipMacroDefinitionBody);
202202
CHECK_PARSE_BOOL(SpacesInSquareBrackets);
203-
CHECK_PARSE_BOOL(SpaceInEmptyBlock);
204203
CHECK_PARSE_BOOL(SpacesInContainerLiterals);
205204
CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
206205
CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
@@ -688,6 +687,17 @@ TEST(ConfigParseTest, ParsesConfiguration) {
688687
SpaceBeforeParens,
689688
FormatStyle::SBPO_ControlStatementsExceptControlMacros);
690689

690+
Style.SpaceInEmptyBraces = FormatStyle::SIEB_Never;
691+
CHECK_PARSE("SpaceInEmptyBraces: Always", SpaceInEmptyBraces,
692+
FormatStyle::SIEB_Always);
693+
CHECK_PARSE("SpaceInEmptyBraces: Block", SpaceInEmptyBraces,
694+
FormatStyle::SIEB_Block);
695+
CHECK_PARSE("SpaceInEmptyBraces: Never", SpaceInEmptyBraces,
696+
FormatStyle::SIEB_Never);
697+
// For backward compatibility:
698+
CHECK_PARSE("SpaceInEmptyBlock: true", SpaceInEmptyBraces,
699+
FormatStyle::SIEB_Block);
700+
691701
// For backward compatibility:
692702
Style.SpacesInParens = FormatStyle::SIPO_Never;
693703
Style.SpacesInParensOptions = {};

0 commit comments

Comments
 (0)