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
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Claudio
  • 3,089
  • 2
  • 18
  • 22
  • 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 06 '14 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 08 '14 at 13:05

1 Answers1

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.

LThode
  • 1,843
  • 1
  • 17
  • 28
  • 1
    Actually the removal of whitespace occurs before the stringize step, in the expansion of _\_VA_ARGS_\_. – Claudio Nov 04 '14 at 17:42