Skip to content

Commit

Permalink
[clang-format] Don't remove parentheses in macro definitions (#81444)
Browse files Browse the repository at this point in the history
Closes #81399.
  • Loading branch information
owenca authored Feb 13, 2024
1 parent 542a3cb commit 4af24d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
parseChildBlock();
break;
case tok::r_paren:
if (!MightBeStmtExpr &&
if (!MightBeStmtExpr && !Line->InMacroBody &&
Style.RemoveParentheses > FormatStyle::RPS_Leave) {
const auto *Prev = LeftParen->Previous;
const auto *Next = Tokens->peekNextToken();
Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26972,6 +26972,7 @@ TEST_F(FormatTest, RemoveParentheses) {
EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);

Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
verifyFormat("#define Foo(...) foo((__VA_ARGS__))", Style);
verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
verifyFormat("decltype((foo->bar)) baz;", Style);
verifyFormat("class __declspec(dllimport) X {};",
Expand Down Expand Up @@ -27006,6 +27007,7 @@ TEST_F(FormatTest, RemoveParentheses) {
verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);

Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
verifyFormat("#define Return0 return (0);", Style);
verifyFormat("return 0;", "return (0);", Style);
verifyFormat("co_return 0;", "co_return ((0));", Style);
verifyFormat("return 0;", "return (((0)));", Style);
Expand Down

0 comments on commit 4af24d4

Please sign in to comment.