On Mon, Aug 15, 2022 at 04:03:13PM -0400, Jason Merrill wrote: > On 8/13/22 14:35, Marek Polacek wrote: > > This patch implements the C23 nullptr literal: > > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm>, which is > > intended to replace the problematic definition of NULL which might be > > either of integer type or void*. > > > > Since C++ has had nullptr for over a decade now, it was relatively easy > > to just move the built-in node definitions from the C++ FE to the C/C++ > > common code. Also, our DWARF emitter already handles NULLPTR_TYPE by > > emitting DW_TAG_unspecified_type. However, I had to handle a lot of > > contexts such as ?:, comparison, conversion, etc. > > > > There are some minor differences, e.g. in C you can do > > > > bool b = nullptr; > > > > but in C++ you have to use direct-initialization: > > > > bool b{nullptr}; > > > > And I think that > > > > nullptr_t n = 0; > > > > is only valid in C++. > > > > Of course, C doesn't have to handle mangling, RTTI, substitution, > > overloading, ... > > > > This patch also defines nullptr_t in <stddef.h>. I'm uncertain about > > the __STDC_VERSION__ version I should be checking. Also, I'm not > > defining __STDC_VERSION_STDDEF_H__ yet, because I don't know what value > > it should be defined to. Do we know yet? > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > The C++ changes are OK, but you probably want a comment in > c_common_nodes_and_builtins that we aren't setting the alignment there for > C++ backward ABI bug compatibility. Or perhaps set it there and then break > it in the C++ front end when abi < 9.
Thanks! I added a comment to that effect in the v2 patch I just posted. Marek