improving C++ libc headers
Lexi Winter <[email protected]>
| Newsgroups | gmane.os.freebsd.architechture |
|---|---|
| Message-ID | <[email protected]> |
hi list,
i am considering working up a patch to improve C++ libc headers in FreeBSD.
the problem with the current headers (which come from clang/libc++) is
that this code compiles:
------
#include <cstdlib>
auto main() -> int {
exit(0);
}
------
this should be a compile-time error, because <cstdio> does not declare
::exit[0]. however, it works because <cstdlib> is implemented like
this:
------
#include <stdlib.h> // exposes ::exit()
namespace std {
using ::exit;
// ...
}
------
i would like to replace this with an implementation that does this
instead:
------
namespace std {
extern "C" void exit(int);
// ...
}
------
i have done a very quick proof of concept for this and it does work;
there are some more complicated edge cases, but nothing that can't be
dealt with from what i can see.
but before i put any amount of significant effort into this, i'd like to
check if this is something that is likely to be merged.
to address some potential objections:
- i don't believe this can be handled upstream in libc++, because some
of these headers require knowledge of the implementation - <cstdio>
needs to know about 'struct __sFILE', for example.
- "import std" should solve this properly, but there are a lot of
implementation issues with this and it's not clear if/when it will
ever be supported; in the mean time, the existing standard headers
should behave correctly.
[0] https://www.eel.is/c++draft/cstdlib.syn#header:%3Ccstdlib%3E
[1] https://cgit.freebsd.org/src/tree/contrib/llvm-project/libcxx/include/cstdlib
signature.asc
(application/pgp-signature, 659 B)
-----BEGIN PGP SIGNATURE----- iQGzBAABCAAdFiEEuwt6MaPcv/+Mo+ftDHqbqZ41x5kFAmW4+gsACgkQDHqbqZ41 x5n1RAv/X0qs0gIRVtIM7tAfxJi7CFPmEgWH4crfPIpEQT+X3SfgDSO0HAMvleqt POidCb2xwAZ9xJ4AFBd0dL8U/BUfEfG4pRRkllku2SfQdf1VTx+gKi1kfNXnzWUq pEdZQSTI+oTy1lHraddimLV6aM+UrTH6KLCenwhkZcCtP5q11LiG7k3JJjfGKVYo vhlXWMz5qCy3tjU13/XeAP7BiuqCbcnwrJSa4Hxe8COOMwMmyl75BRIV1x/46ODG Xbnlv/poxl1bS0XwjYp+PkLFA6nR3jcb1P04mxcZqnF0fqAvGHTNVfI5/OXhHbZM H3jLHzpDRoTl9hyAGiL5uEPgWVatG4Qyjdteffk1HYupcEjr6TSOliCD0BGPGdLe UwN+EjnuIymRmbN0oLMGoSvRV5QkTig4DaaKSmiyHDYco8iZ2pmTg3mqnv0Pa3uI adXelkf2/GOgXWGkp1MO4du7Xr3hisdN565H3WbGTfhBbCl3N6GXdPdo6YJo3OJ2 WmwaP51e =so+Z -----END PGP SIGNATURE-----