<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/73598>73598</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [preprocessor] Clang doesn't warn about preprocessing directives in function-like macro arguments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          StephanTLavavej
      </td>
    </tr>
</table>

<pre>
    [N4964](https://isocpp.org/files/papers/N4964.pdf) \[cpp.replace.general\]/13:

> The sequence of preprocessing tokens bounded by the outside-most matching parentheses forms the list of arguments for the function-like macro. The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens between matching inner parentheses do not separate arguments. If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives, the behavior is undefined.

When preprocessing directives are embedded in function-like macro arguments, MSVC appears to reject with its traditional (horribly deficient) preprocessor, and emits a dedicated warning with its modern (more conformant) preprocessor (and then later rejects, at least some of the time). Clang appears to silently accept, which is surprising.

```
C:\Temp>type meow.cpp
```
```cpp
#include <cstdio>

#define OUTER_MACRO(ARG) std::puts(ARG)

int main() {
    OUTER_MACRO("I have "
#ifdef MANY
 "1729"
#else
                 "5"
#endif
                " cute fluffy kittens.");
}
```
```
C:\Temp>cl /EHsc /nologo /W4 meow.cpp && meow
meow.cpp
meow.cpp(12): error C2121: '#': invalid character: possibly the result of a macro expansion
meow.cpp(6): error C2146: syntax error: missing ')' before identifier 'ifdef'
meow.cpp(6): error C2146: syntax error: missing ';' before identifier 'ifdef'
meow.cpp(6): error C2065: 'ifdef': undeclared identifier
meow.cpp(6): error C2146: syntax error: missing ';' before identifier 'MANY'
meow.cpp(6): error C2065: 'MANY': undeclared identifier
meow.cpp(6): error C2143: syntax error: missing ';' before 'string'
meow.cpp(6): error C2143: syntax error: missing ';' before 'else'
meow.cpp(12): error C2181: illegal else without matching if
meow.cpp(6): error C2146: syntax error: missing ';' before identifier 'endif'
meow.cpp(6): error C2065: 'endif': undeclared identifier
meow.cpp(6): error C2059: syntax error: ')'

C:\Temp>cl /EHsc /nologo /W4 /Zc:preprocessor meow.cpp && meow
meow.cpp
meow.cpp(7): warning C5101: use of preprocessor directive in function-like macro argument list is undefined behavior
meow.cpp(9): warning C5101: use of preprocessor directive in function-like macro argument list is undefined behavior
meow.cpp(11): warning C5101: use of preprocessor directive in function-like macro argument list is undefined behavior
meow.cpp(6): error C2143: syntax error: missing ')' before '#'
meow.cpp(6): error C2143: syntax error: missing ';' before '#'
meow.cpp(6): error C2059: syntax error: '#'
meow.cpp(6): error C2059: syntax error: ')'

C:\Temp>clang-cl /EHsc /nologo /W4 meow.cpp && meow
I have 5 cute fluffy kittens.

C:\Temp>clang-cl -v
clang version 16.0.5
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\Llvm\x64\bin
```

This allowed UB to accumulate in libc++'s test suite, see #73440.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWF9v2zgS_zT0C2FDoizLfvCDI8d3C2x2D222i7uXBUWOLG4pUkdSdvLtD0Mr_pO4TZNe0SCwTXH4429mOMMZce_V1gAsSX5D8vWI96GxbvkxQNdwc_8r3_Ed_D2qrHxEkd-mi9mU5GvC5k0InSfZirANYRvlrei6iXVbwja10uAJ23S8A4c_4rJJJ2vCFpTkJclvUNpBp7mAyRYMOK7jxJqwTZohbrImydNndkvvG6Ae_tuDEUBtTTsHnbMCvFdmS4P9DMbTyvZGgqTVIw0NUNsHrySMW-sDbXkQDcp23IEJDXjwtLau9VFWKx8Ql7tt34IJcS7O1L0RQVkz1uoz0JYLZyeRjjJS7ZTsuT5btVehUeYEyR3y7rjj4UBM2LblV-kTVtKqD1-RoBWEPYA5KaOMAXehkrTU2HDc80RtQn-pkZeDgdTBmP6L1nyuyoV1QsMD3dteS2oR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