[clang] Diagnose the code with trailing comma in the function call. (PR #125232)
Björn Pettersson via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 17 04:19:40 PST 2025
bjope wrote:
This seems to break something with variadic args and the gcc hack with ## to ignore the trailing comma error:
```
#include <stdio.h>
#define debug_ok(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
void foo() {
debug_ok("qwerty");
}
#define debug_nok(...) fprintf(stderr, "qwerty", ## __VA_ARGS__)
void bar() {
debug_nok();
}
```
At least with `-std=c23` we get this:
```
<source>:9:5: error: expected expression
9 | debug_nok();
| ^
<source>:7:64: note: expanded from macro 'debug_nok'
7 | #define debug_nok(...) fprintf(stderr, "qwerty", ## __VA_ARGS__)
| ^
1 error generated.
Compiler returned: 1
```
See godbolt test here: https://godbolt.org/z/fejP1oa1f
But given that there is a difference between the foo and bar tests maybe I've missed some special rule for when this variadic macro solution with ## applies.
https://github.com/llvm/llvm-project/pull/125232
More information about the cfe-commits
mailing list