ned14 / status-code

Proposed SG14 status_code for the C++ standard
Other
64 stars 13 forks source link

weird compile error related to implicit conversions & exception throw #38

Closed lzhangzz closed 2 years ago

lzhangzz commented 3 years ago

I'm getting really weird compile error when constructing system_error2::error from enums through multiple implicit conversions, well it's best explained in code:

https://godbolt.org/z/aEqKbxK6c

The throw in the inlined _do_throw_exception caused the problem, if it's removed or moved into some implementation file, the problem is gone. Is this somehow related to some exception specifications somewhere?

ned14 commented 2 years ago

No it's almost certainly a parse bug in clang only, as it works fine in GCC or MSVC.

It seems to depend on where in the file the throw is. See https://godbolt.org/z/xcjehPaec.

It doesn't occur if the throw doesn't mention its base class. See https://godbolt.org/z/soYKMW5Pr

At least you now have a workaround: define your throw exception method a little later after anything which affects SFINAE.

Incidentally, I've seen this parse ordering bug and throw in clang before, though not in this context. It affects every version of clang from the beginning until the most recent. One should really make them a contained repro, though clang is now the worst for timely fixes of compiler bugs of the three major compilers.

I'm going to close this as I think this a compiler bug. Hope the workaround works for you.