11

The C++ preprocessor of Oracle Solaris Studio 12.3 removes whitespace completely when expanding __VA_ARGS__.

Can anybody confirm this behaviour on their system? Is it a known compiler bug? Are there any workarounds for this problem?

To illustrate, here is a simple test program, vaargs.c:

#include <stdio.h>

#define PRINT(...) printf("%s\n", #__VA_ARGS__)

int main()
{
    PRINT(hello world);

    return 0;
}

The C preprocessor works as expected:

$ cc vaargs.c -o vaargs && ./vaargs
hello world

$ cc -V
cc: Sun C 5.12 SunOS_i386 2011/11/16

But the C++ preprocessor removes the space between "hello" and "world":

$ CC vaargs.c -o vaargs && ./vaargs
helloworld

$ CC -V
CC: Sun C++ 5.12 SunOS_i386 2011/11/16
2
  • 3
    Both clang (3.5) and GCC (4.9.1) output hello world (for both C and C++) for me. I don't have Solaris Studio so I can't confirm with that.
    – Cornstalks
    Oct 6, 2014 at 19:27
  • It does appear to be an issue with the Solaris Studio 12.3 C++ preprocessor. The problem does not occur with the previous version (12.2).
    – Claudio
    Oct 8, 2014 at 13:05

1 Answer 1

4

This is a compiler bug, as per N3337 16.3.2 (cpp.stringize) p2 (the rest of the quote is snipped):

A character string literal is a string-literal with no prefix. If, in the replacement list, a parameter is immediately preceded by a # preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument. Each occurrence of white space between the argument’s preprocessing tokens becomes a single space character in the character string literal.

1
  • 1
    Actually the removal of whitespace occurs before the stringize step, in the expansion of __VA_ARGS__.
    – Claudio
    Nov 4, 2014 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.