[dev-context] luametatex compiled with g++

Schultheis Erik erik.schultheis at aalto.fi
Mon Dec 12 14:11:39 CET 2022


I'm not sure if this is the right list, if not please redirect me.

So, I tried compiling luametatex using g++, and noticed some things that prevent it from also being considered valid C++ code.

Two general problems are:

1) Initialization order. C++ wants initializers to be specified in the order in which they will actually initialize the object, i.e. in the order of the members.

2) Reserved names. Some variables are named `class` or `template`, which of course, breaks C++.

But more interesting are the specific pieces of code that get rejected, because C++ is a bit more strict than C in some cases.

3) We get one complaint about comparing a pointer to an integer using <, which  I believe is an actual bug in the code.
4) A second complaint is about dropping const in `tex_to_cstring`. I don't think this causes an actual error in the program, though.
5) Some of the `goto`s cause problems, because the jump skips over the initialization of variables in the target scope. Again, these variables are not used, so I don't think there is an actual error. The easy fix here is to just move the code from the `goto` target into its own function, which is probably better for readability anyway.

6) The last problem is that things break with g++ if the marco `infinity` is defined.

I've attached patches for 3), 4), and 5), as I think that these benefit code quality in general. I can also send ones for 1) and 2), if there is interest. 6) seems to be a more general incompatibility, I'm not sure if there is a "fix" that doesn't require #if s.

Kind regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/dev-context/attachments/20221212/3f0246b4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug.patch
Type: text/x-patch
Size: 620 bytes
Desc: bug.patch
URL: <http://mailman.ntg.nl/pipermail/dev-context/attachments/20221212/3f0246b4/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: const.patch
Type: text/x-patch
Size: 3589 bytes
Desc: const.patch
URL: <http://mailman.ntg.nl/pipermail/dev-context/attachments/20221212/3f0246b4/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: less_goto.patch
Type: text/x-patch
Size: 4578 bytes
Desc: less_goto.patch
URL: <http://mailman.ntg.nl/pipermail/dev-context/attachments/20221212/3f0246b4/attachment-0002.bin>

More information about the dev-context mailing list