syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Stop using runtime C++ exceptions

Open maelhos opened this issue 2 years ago • 8 comments

Replace throw by std::exit

As of LLVM 18, llvm-config --cxxflags contains -fno-exceptions, general standards are also moving out runtime exceptions in C++ as much as possible c.f. stackoverflow discussion.

I can't run test since the dev is broken because of transition from babel 6 to 7 (I don't know enough about babel to update everything to babel 7) and there is no version nor instruction specifying the required npm and node.

maelhos avatar Jan 02 '24 14:01 maelhos

@maelhos, thanks for the contribution! Hopefully this is not a breaking change anywhere (except the cases which may catch for the specific exceptions, but that should be fine). Can you confirm the EXIT_FAILURE in the second case?

DmitrySoshnikov avatar Jan 03 '24 00:01 DmitrySoshnikov

For that you would need stdlib.h, it doesn't seem to be included in this part of the template though it probably is in the final header, I used 1 to play it safe but if you have the ability to test if EXIT_FAILURE works that would be great.

maelhos avatar Jan 03 '24 11:01 maelhos

You can add it here: https://github.com/DmitrySoshnikov/syntax/blob/master/src/plugins/cpp/templates/lr.template.h#L23

Where you able to test the generated code? I'll try looking at https://github.com/DmitrySoshnikov/syntax/issues/141 later if you're blocked on testing, unless you reach that issue earlier.

DmitrySoshnikov avatar Jan 04 '24 07:01 DmitrySoshnikov

I dont't think it is possible to test generation without solving #141 since it happens at compile time though the package syntax-cli available through npm still works fine.

maelhos avatar Jan 04 '24 09:01 maelhos

#141 should be fixed https://github.com/DmitrySoshnikov/syntax/commit/0ec6737c4d813259171706677b83670c4cf9a9da. Can you verify?

DmitrySoshnikov avatar Jan 05 '24 04:01 DmitrySoshnikov

#141 should be fixed 0ec6737. Can you verify?

It's fixed, everything works for me, instead of just exiting we could also make a custom Error Wrapper which could be overwritten by the user (kinda yyerror in bison) would you want that ?

maelhos avatar Jan 06 '24 23:01 maelhos

Yes, good idea - we can probably change it in the follow up PR.

For this one - can you update please to add stdlib.h in https://github.com/DmitrySoshnikov/syntax/blob/master/src/plugins/cpp/templates/lr.template.h#L23 and also change 1 to EXIT_FAILURE?

DmitrySoshnikov avatar Jan 07 '24 05:01 DmitrySoshnikov

Actually, a program should be able to handle parse error at runtime. With the full exit this now changes semantics, right? - you can't catch the parse errors anymore?

DmitrySoshnikov avatar Jan 07 '24 06:01 DmitrySoshnikov