VS2019: Compiling Cap'nProto Crashes C++ Compiler

309 views Asked by At

So, the situation is that due to some unforeseen consequences I need to build Cap'nProto (https://capnproto.org/) for windows using Visual Studio 2019 (latest release as far as I know, 16.7.3).

As you can see from the screenshot below, the compiler is very unhappy with the code, to the extent that it gives an internal compiler error on the line 2616 where there is a pretty complex macro that expands to an auto template nightmare.

Screenshot of Error

The macro itself is:

#define KJ_CASE_ONEOF(name, ...) \
    break; \
  case ::kj::Decay<decltype(*_kj_switch_subject)>::template tagFor<__VA_ARGS__>(): \
    for (auto& name = _kj_switch_subject->template get<__VA_ARGS__>(), *_kj_switch_done = &name; \
         _kj_switch_done; _kj_switch_done = nullptr)

My first attempt wast to manually fix this occurrence (and the the next ones in this file with something on the lines of extracting the two variable definitions outside the for, and adding an extra pair of scopes (without touching the macro actually) but the next compilation stage revealed that sadly this macro is literally used everywhere in the application. BTW, this strategy worked, the compiler did not crash anymore.

But due to that strategically placed maleficent break, (easily) rewriting the macro following aforementioned strategy proved to be a bit harder than I thought.

Now, I could report the error and wait for Microsoft to fix its compiler, however considering that I need this compiled ... yesterday that is not an option for now.

Capnproto on their website (https://capnproto.org/install.html#supported-compilers) claims that they support Visual Studio 2017, sadly that is not an option for me either.

The other solution which I chose is to ask the community if anyone has any other idea on how to rewrite that macro in order to perturbate a bit the macro generated code while it still will have the same meaning, just expressed differently (I tried adding more variables, in the line of **dummy = &kj_switch_done but it still gives a compiler crash).

Any ideas?

1

There are 1 answers

0
chronoxor On BEST ANSWER

This is a Work around VS2019 ICE in KJ_CASE_ONEOF() that on code review now and hope soon will be merged into master