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.

(cherry picked from commit 4af24d4)
  • Loading branch information
owenca authored and tstellar committed Feb 16, 2024
1 parent 872fe20 commit ab57f6c
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 @@ -2515,7 +2515,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 @@ -26856,6 +26856,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 @@ -26890,6 +26891,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 ab57f6c

Please sign in to comment.