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

    <tr>
        <th>Summary</th>
        <td>
            [clang] the error preprocessing directive doesn't handle whitespace and multiline comments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    According to the C11 spec, whitespace is handled in translation phase 3, i.e. before the preprocessor runs. Consequently, one can write preprocessing directives spanning multiple lines, as long as the line feed characters are enclosed in multiline comments (`/* ... */`). E.g. this is valid C11:

```
#if  /*
                 */ 1
int main() {
        return 0;
}

#else

ffsdfsdfsdf

#endif
```

And clang handles it correctly.

However, `#error` preprocessor directives, unlike other directives, in Clang seem to not skip whitespace at all. E.g. this directive in Clang preserves all the duplicated spaces in the printed diagnostic:

```
#error one         two
```

(GCC doesn't preserve duplicated spaces in its output.)

And the following program results in two compilation errors instead of one:
```
#error one two /*
        */ three
```
Clang, when compiling this program, prints:
```
<source>:1:2: error: one two /*
#error one two /*
 ^
<source>:2:3: error: expected identifier or '('
        */ three
 ^
2 errors generated.
```

While GCC prints:
```
<source>:1:2: error: #error one two three
    1 | #error one two /*
      |  ^~~~~
Compiler returned: 1
```

I believe GCC is correct here, since, according to the spec, whitespace (including comments) should be handled before the preprocessor runs, and according to the spec (6.10.5), the `#error` directive accepts tokens (not raw input until end of line).

I compiled all code using ` clang -std=c11`. Locally I used Clang 13 (shipped with XCode). Tested on godbolt.org that the issue is present in Clang 16 as well.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVs2O4zYMfhrlQqxhy-MkPuSQzey0C_RYoL3KEhOzo0iuJE86l3n2gnIy-dlsemgQ-EeiyY_kR1IqRto5xJVovormeabG1PuwelevY0du1nnzvlpr7YMht4PkIfUIm6qCOKAWc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