[build2] [bug] Compilation error not visible in the reported file (wrong file reported?)

Boris Kolpackov boris at codesynthesis.com
Wed Mar 21 14:56:44 UTC 2018

Klaim - Joël Lamotte <mjklaim at gmail.com> writes:

> By the way, it seems that just not using litteral strings should work?
> They can be replaced by normal strings and escaping I believe. If that's
> the source of the issue, I can do that modification.

Yes, though this case is exactly where you really want to use raw string
literals. Using normal literals with escaping here will get pretty hairy.

> Or changing some compiler flags? I don't understand how CMake manage to
> generate a compiler invocation that seem to build correctly.

The source file can be compiled, just not preprocessed (which is a bug
in VC). CMake doesn't do separate preprocessing while build2 does. You
can read more about the reasons here:


Ok, now about the workaround (which will require the latest staged
toolchain, BTW):

You can ask build2 to no use the result of (partial) preprocessing in
compilation with cc.reprocess flag (there is also config.cc.reprocess
if you want to force this externally). You can set it on the per-
translation unit or for all translation units in a project, for

obj{foo}: cc.reprocess = true

obj{*}: cc.reprocess = true

If a translation unit is compiled with reprocessing, then build2 also
defines __build2_preprocess macro during preprocessing. The idea is
to #ifdef-out problematic fragments using this macro. As long as it
does not affect #include or module information, it is safe to do since
the result of preprocessing (which now may have chunks of code missing)
won't actually be used for compilation proper.

Note that there are number of disadvantages of forcing reprocessing:

1. Slight performance penalty since (partially) preprocessed output
   cannot be reused.

2. No support for detection of ignorable changes (e.g., changes in
   comments, whitespaces, etc).

3. In the future such translation units won't be eligible for
   distributed compilation.

As a result, you probably want to limit this only to translation
units that actual need it and also only for problematic compilers.
Something along these lines:

if ($cxx.id == 'msvc')
  obj{foo bar}: cc.reprocess = true

Previous discussion of a similar issue:



More information about the users mailing list