[clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (#85470)
This resolves an issue in clang-format where `new` and `delete` were incorrectly formatted as keywords in C files. The fix modifies `TokenAnnotator::spaceRequiredBetween` to handle `new` and `delete` when used as identifiers for function pointers in structs in C code.
This commit is contained in:
@@ -4613,7 +4613,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
||||
return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
|
||||
spaceRequiredBeforeParens(Right);
|
||||
}
|
||||
if (!Left.Previous || Left.Previous->isNot(tok::period)) {
|
||||
if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
|
||||
if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
|
||||
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
|
||||
spaceRequiredBeforeParens(Right);
|
||||
|
||||
@@ -11475,6 +11475,11 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
|
||||
"void new (link p);\n"
|
||||
"void delete (link p);");
|
||||
|
||||
verifyFormat("{ p->delete(); }\n"
|
||||
"{ p->new(); }",
|
||||
"{ p->delete (); }\n"
|
||||
"{ p->new (); }");
|
||||
|
||||
FormatStyle AfterPlacementOperator = getLLVMStyle();
|
||||
AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
|
||||
EXPECT_TRUE(
|
||||
|
||||
Reference in New Issue
Block a user