Skip to content

Commit 195279c

Browse files
dmcppcheckclaude
andcommitted
HideSetExpander: remove the comma before an empty __VA_ARGS__
Same as the old expansion (cppcheck trac #9754). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 58c9a43 commit 195279c

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎simplecpp.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,10 @@ namespace simplecpp {
34053405
TokenList operand(files);
34063406
getOperand(operand, macro, tok, call, expand);
34073407
const bool empty = operand.empty();
3408+
// an empty __VA_ARGS__ at the end of a call removes the comma before it
3409+
if (empty && !hashHash && parameter && operandTok->str() == "__VA_ARGS__" && result.back() && result.back()->str() == "," &&
3410+
operandTok->nextSkipComments() && operandTok->nextSkipComments()->str() == ")")
3411+
result.deleteToken(result.back());
34083412
if (hashHash)
34093413
paste(result, operand, previousEmpty, macro, hashHash, operandTok);
34103414
else

‎test.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,6 @@ static void define_va_args_3() // min number of arguments
15061506

15071507
static void define_va_args_4() // cppcheck trac #9754
15081508
{
1509-
HIDESET_EXPANSION_TODO(); // comma before an empty __VA_ARGS__
15101509
const char code[] = "#define A(x, y, ...) printf(x, y, __VA_ARGS__)\n"
15111510
"A(1, 2)\n";
15121511
ASSERT_EQUALS("\nprintf ( 1 , 2 )", preprocess(code));

0 commit comments

Comments
 (0)