Skip to content

Commit 4af24d4

Browse files
authored
[clang-format] Don't remove parentheses in macro definitions (llvm#81444)
Closes llvm#81399.
1 parent 542a3cb commit 4af24d4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

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

clang/unittests/Format/FormatTest.cpp

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

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

2700827009
Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
27010+
verifyFormat("#define Return0 return (0);", Style);
2700927011
verifyFormat("return 0;", "return (0);", Style);
2701027012
verifyFormat("co_return 0;", "co_return ((0));", Style);
2701127013
verifyFormat("return 0;", "return (((0)));", Style);

0 commit comments

Comments
 (0)