Skip to content

Commit ab57f6c

Browse files
owencatstellar
authored andcommitted
[clang-format] Don't remove parentheses in macro definitions (llvm#81444)
Closes llvm#81399. (cherry picked from commit 4af24d4)
1 parent 872fe20 commit ab57f6c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Diff for: clang/lib/Format/UnwrappedLineParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
25152515
parseChildBlock();
25162516
break;
25172517
case tok::r_paren:
2518-
if (!MightBeStmtExpr &&
2518+
if (!MightBeStmtExpr && !Line->InMacroBody &&
25192519
Style.RemoveParentheses > FormatStyle::RPS_Leave) {
25202520
const auto *Prev = LeftParen->Previous;
25212521
const auto *Next = Tokens->peekNextToken();

Diff for: clang/unittests/Format/FormatTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -26856,6 +26856,7 @@ TEST_F(FormatTest, RemoveParentheses) {
2685626856
EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);
2685726857

2685826858
Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
26859+
verifyFormat("#define Foo(...) foo((__VA_ARGS__))", Style);
2685926860
verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
2686026861
verifyFormat("decltype((foo->bar)) baz;", Style);
2686126862
verifyFormat("class __declspec(dllimport) X {};",
@@ -26890,6 +26891,7 @@ TEST_F(FormatTest, RemoveParentheses) {
2689026891
verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);
2689126892

2689226893
Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
26894+
verifyFormat("#define Return0 return (0);", Style);
2689326895
verifyFormat("return 0;", "return (0);", Style);
2689426896
verifyFormat("co_return 0;", "co_return ((0));", Style);
2689526897
verifyFormat("return 0;", "return (((0)));", Style);

0 commit comments

Comments
 (0)