Date: Tue, 30 Jan 2024 11:12:16 -0800 From: Enji Cooper <yaneurabeya@gmail.com> To: Lexi Winter <lexi@le-fay.org> Cc: freebsd-arch@freebsd.org Subject: Re: improving C++ libc headers Message-ID: <7D5B040A-688E-47EA-8BF6-04AA18477399@gmail.com> In-Reply-To: <Zbj6DuTgT7i88Zkd@ilythia.eden.le-fay.org> References: <Zbj6DuTgT7i88Zkd@ilythia.eden.le-fay.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> On Jan 30, 2024, at 05:31, Lexi Winter <lexi@le-fay.org> wrote: >=20 > =EF=BB=BFhi list, >=20 > i am considering working up a patch to improve C++ libc headers in FreeBSD= . >=20 > the problem with the current headers (which come from clang/libc++) is > that this code compiles: >=20 > ------ > #include <cstdlib> > auto main() -> int { > exit(0); > } > ------ >=20 > this should be a compile-time error, because <cstdio> does not declare > ::exit[0]. however, it works because <cstdlib> is implemented like > this: >=20 > ------ > #include <stdlib.h> // exposes ::exit() >=20 > namespace std { > using ::exit; > // ... > } > ------ >=20 > i would like to replace this with an implementation that does this > instead: >=20 > ------ > namespace std { > extern "C" void exit(int); > // ... > } > ------ >=20 > 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. >=20 > 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. >=20 > to address some potential objections: >=20 > - 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. >=20 > - "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. >=20 > [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 Hi Lexi! That=E2=80=99s an interesting proposal! Given that this is a third-party library, I think it=E2=80=99s best to submi= t this proposal and patches up to the LLVM project (there are some folks in t= he FreeBSD project who are connected to LLVM, but arch is a wider distributi= on of folks and might not overlap with those individuals). The proposal woul= d be beneficial to multiple OSes=E2=80=94not just FreeBSD. Moreover, you mig= ht be able to convince others in the LLVM project to work with you to achiev= e the desired outcome sooner. Thank you again for sharing and starting this discussion! Cheers! -Enji
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7D5B040A-688E-47EA-8BF6-04AA18477399>