Skip to content

spaces are incorrectly elided in strings defined by macros #5

Open
@bcantrill

Description

@bcantrill

Take the following:

$ cat wtf.cpp
#define WTF     "    this    is     a    string     with      spaces"

"    this    is     a    string     with      spaces"
WTF

This is the kind of output we would expect:

$ cat wtf.cpp | /opt/gcc-12/bin/cpp
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "<stdin>"


"    this    is     a    string     with      spaces"
"    this    is     a    string     with      spaces"

In antiquarian CPP, however:

$ cat wtf.cpp | ./cpp/src/cpp
# 1 "" 


"    this    is     a    string     with      spaces"
" this is a string with spaces"

This is due to fixing TritonDataCenter/smartos-live#171, and in particular, this code:

cpp/src/cpp.c

Lines 1307 to 1318 in f75fd24

/*
* If we're mid-paste, compress spaces to a
* single space
*/
while (isspace(*vp)) {
if (!isspace(vp[1])) {
*vp = ' ';
break;
} else {
vp--;
}
}

Unforunately, this behavior is causing a DTrace test suite failure, as macros in https://github.com/illumos/illumos-gate/blob/master/usr/src/cmd/dtrace/test/tst/common/json/tst.general.d contain spaces that are being incorrectly elided.

It's unclear how hard this would be to fix or if the cure is worse than the disease on this one. If DTrace is the only consumer (but it sounds like as is also still a consumer?), it would probabably be be worth moving to an ANSI-compatible CPP in /usr/lib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions