Summary
mcpp emit build-database --format json puts shell-escaped quotes inside the arguments
array. A JSON arguments array is passed to exec without a shell, so its elements must be
unescaped; the backslashes reach the compiler as literal characters.
Consumers that honour arguments (clangd's module scanner, any tool driving the database) then fail
to parse every translation unit that uses a quoted macro define.
Reproduce
In a project whose build defines a macro to a quoted string — openxlings/xlings does, through its
vendored libarchive:
$ mcpp emit build-database --format json > db.json
$ python3 -c "
import json
d = json.load(open('db.json'))
def walk(o):
if isinstance(o, dict):
for v in o.values(): yield from walk(v)
elif isinstance(o, list):
for v in o: yield from walk(v)
elif isinstance(o, str): yield o
for s in walk(d):
if 'PLATFORM_CONFIG_H' in s: print(repr(s)); break
"
'-DPLATFORM_CONFIG_H=\\"mcpp_libarchive_config.h\\"'
The field is arguments, and its type is a list:
字段名: arguments | 类型: list
元素: '-DPLATFORM_CONFIG_H=\\"mcpp_libarchive_config.h\\"'
So the actual element is:
-DPLATFORM_CONFIG_H=\"mcpp_libarchive_config.h\"
Expected
-DPLATFORM_CONFIG_H="mcpp_libarchive_config.h"
The quotes belong to the macro's value (the source does #include PLATFORM_CONFIG_H, which needs
"..." or <...>). Escaping is a shell concern, and arguments does not go through a shell.
What it breaks
With the backslashes literal, the macro expands to \"mcpp_libarchive_config.h\" and every TU
including it fails:
archive_platform.h:44:10: error: expected "FILENAME" or <FILENAME>
<built-in>:418:27: note: expanded from macro 'PLATFORM_CONFIG_H'
archive_platform.h:164:2: error: No suitable 32-bit unsigned integer type found for this platform
archive_platform.h:173:2: error: No suitable 32-bit signed integer type found for this platform
In openxlings/xlings this is every C file of libarchive, bzip2, lz4, xz, zlib and zstd. For a
language server the consequences are that those files never get an index (no navigation into them),
and the scanner retries and logs the failure repeatedly.
Environment
- mcpp 2026.9.16.1
- Project:
openxlings/xlings (linux x86_64, gcc 16.1.0 profile)
- Consumer: mcpp-language-server, which reads
arguments as exec-ready per the S1 build database
contract
Note
If arguments is intended to carry shell-quoted text — i.e. consumers are expected to shell-split
and unescape it — then this is a documentation issue instead, and I would like to know, because the
distinction decides whether consumers should unescape defensively. command (a string) and
arguments (a list) usually differ exactly here, which is why we read it as exec-ready.
Summary
mcpp emit build-database --format jsonputs shell-escaped quotes inside theargumentsarray. A JSON
argumentsarray is passed toexecwithout a shell, so its elements must beunescaped; the backslashes reach the compiler as literal characters.
Consumers that honour
arguments(clangd's module scanner, any tool driving the database) then failto parse every translation unit that uses a quoted macro define.
Reproduce
In a project whose build defines a macro to a quoted string —
openxlings/xlingsdoes, through itsvendored libarchive:
The field is
arguments, and its type is a list:So the actual element is:
Expected
The quotes belong to the macro's value (the source does
#include PLATFORM_CONFIG_H, which needs"..."or<...>). Escaping is a shell concern, andargumentsdoes not go through a shell.What it breaks
With the backslashes literal, the macro expands to
\"mcpp_libarchive_config.h\"and every TUincluding it fails:
In
openxlings/xlingsthis is every C file of libarchive, bzip2, lz4, xz, zlib and zstd. For alanguage server the consequences are that those files never get an index (no navigation into them),
and the scanner retries and logs the failure repeatedly.
Environment
openxlings/xlings(linux x86_64, gcc 16.1.0 profile)argumentsas exec-ready per the S1 build databasecontract
Note
If
argumentsis intended to carry shell-quoted text — i.e. consumers are expected to shell-splitand unescape it — then this is a documentation issue instead, and I would like to know, because the
distinction decides whether consumers should unescape defensively.
command(a string) andarguments(a list) usually differ exactly here, which is why we read it as exec-ready.