Issue 157318
Summary Concatenating a placemarker token with a comma should result in a comma
Labels new issue
Assignees
Reporter Halalaluyafail3
    The following program is not preprocessed correctly by Clang:
```c
#define C(...),##__VA_ARGS__
int main(void){
    1 C()2;
}
```
Currently, Clang will expand `C()` to nothing which causes this program to be invalid.
> If, in the replacement list of a function-like macro, a parameter is immediately preceded or followed
by a ## preprocessing token, the parameter is replaced by the corresponding argument’s preprocessing
token sequence; however, if an argument consists of no preprocessing tokens, the parameter is
replaced by a placemarker preprocessing token instead.
>
> For both object-like and function-like macro invocations, before the replacement list is reexamined
for more macro names to replace, each instance of a ## preprocessing token in the replacement list
(not from an argument) is deleted and the preceding preprocessing token is concatenated with the
following preprocessing token. Placemarker preprocessing tokens are handled specially: concatenation
of two placemarkers results in a single placemarker preprocessing token, and concatenation
of a placemarker with a non-placemarker preprocessing token results in the non-placemarker preprocessing token.
...

Section 6.10.5.3 "The ## operator" Paragraphs 2 and 3 ISO/IEC 9899:2024

`__VA_ARGS__` gets replaced with a placemarker token, so concatenating a comma with it should result in the comma. Hence, this program should be valid as `C()` should become `,`. GCC sometimes gets this correct, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121838. Note that this is specific to comma, e.g. the following is correctly preprocessed:
```c
#define C(...)+##__VA_ARGS__
int main(void){
    1 C()2;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to