Because it does.
To say that whitespace "never matters" in any C++ construct is foolhardy. For example, the following pieces of code are not the same, and I don't believe that anyone would expect them to be:
1.
int x = 42;
2.
intx=42;
It is more true to say that newlines and space characters are generally treated in the same way, but that's still not quite right. Like:
3.
void foo() // a comment
{
4.
void foo() // a comment {
Of course, in this case, the reason the snippets aren't the same is because //
takes effect until the end of the line.
But so does #
.
Both constructs are resolved by the preprocessor, not by the compiler, and the preprocessor works in lines. It is not until later in the build process that more complex parsing takes place. This is logical, consistent, predictable, and practical. All syntax highlighters expect it to work that way.
Could the preprocessor be modified to treat a {
at the end of a preprocessor directive as if it were written on the next line? Sure, probably. But it won't be.
Thinking purely about this actual example, the range of acceptable parameters to a #pragma
is implementation defined (in fact this is the whole point of the #pragma
directive), so it is literally not possible for the C++ standard to define a more complex set of semantics for it than "use the whole line, whatever's provided". And, without the C++ standard guiding it, such logic would potentially result in the same source code meaning completely different things on completely different compilers. No thanks!