Plans for c++23

160 views
Skip to first unread message

Andrew Grieve

unread,
Jan 9, 2025, 8:25:09 PMJan 9
to cxx
We had two recent crashes caused by constructing a std::string from a nullptr.

This looks to be made into a compile error in c++23.

Wondering if chromium is close to being able to move to that, or if not, if there's a way to enable this behaviour for our current code?

Nico Weber

unread,
Jan 9, 2025, 9:01:22 PMJan 9
to Andrew Grieve, cxx
We've adopted every C++ language version since C++11 about 3 years after it was ratified (despite usually trying to be faster). Even then, that tended to cause issues with other toolchains not being ready yet. So I'd expect this to be another 1-3 years out.

https://reviews.llvm.org/D106801 looks like libc++ has a hard check for language version. Maybe they'd accept a patch to force that on in earlier versions, but I wouldn't bet on it.

However, that check is completely static – it detects `string s = nullptr` but not `string s = a` where a happens to be a null pointer. Is a static nullptr really what we hit in practice?



--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABiQX1V7i%2BP05%3DoBotuZaRN%2BJ30cpFR4eJKR22%2BthaBmm1bGdg%40mail.gmail.com.

Andrew Grieve

unread,
Jan 9, 2025, 9:10:59 PMJan 9
to Nico Weber, Andrew Grieve, cxx
Yes, both crashes were due to converting existing JNI code that returned a jstring (which is a pointer) to returning std::string. These refactorings are pretty mechanical, and the recent one was semi-automated. The fact that "return nullptr" turns into a runtime crash is very unfortunate when converting for these conversions.

Thanks for finding the patch. Likes like we'd need only a few lines... Do you think it'd be okay to patch our copy of std::string to have this change?

Nico Weber

unread,
Jan 9, 2025, 11:57:27 PMJan 9
to Andrew Grieve, cxx
We have an automated read-only mirror of upstream libc++ to make it impossible for us to have a local diff, so that's sadly not possible :/

Peter Kasting

unread,
Jan 10, 2025, 9:45:12 PMJan 10
to Nico Weber, Andrew Grieve, cxx
I started kicking the tires on c++23 recently, and it seems mostly baked and not TOO hard to get to. If we want to, it would probably be feasible to take it around August/September, with Clang 21 and the annual AOSP upgrade. However, I also got immediate feedback that c++23 isn't a priority and I shouldn't spend time on it, so if ATLs want to do that, it needs to be an explicit decision. Otherwise I'm not going to bother doing the compat work for it for the foreseeable future, and I don't know of anyone else planning to drive these upgrades.

PK

Nico Weber

unread,
Jan 14, 2025, 2:46:44 PMJan 14
to Andrew Grieve, cxx
We talked about this particular diagnostic a bit in the libc++ discord channel ([1]). It didn't immediately lead to something, but maybe we can get a warning for this in the next few months, without having to bump language versions.

One thing I forgot to mention: You can of course always locally patch up third_party/libc++/src/include/{string,string_view} to make these std::nullptr_t ctors (and assignment ops) deleted and locally build to make sure that there are no problems at the moment. It won't catch new issues, but if you're mostly done with your JNI rewrite, that could give you at least some peace of mind.

Andrew Grieve

unread,
Jan 16, 2025, 2:47:25 PMJan 16
to Nico Weber, Andrew Grieve, cxx
Patching locally is a good idea for these migrations. Thanks for that idea :)

Nico Weber

unread,
Mar 3, 2025, 12:58:36 PMMar 3
to Andrew Grieve, cxx
Closure: https://github.com/llvm/llvm-project/pull/122790 made libc++ warn on nullptrs passed to strings. https://chromium-review.googlesource.com/c/chromium/src/+/6309608 is the cleanup for it. Hopefully we'll roll it in soon :)

Andrew Grieve

unread,
Mar 3, 2025, 3:10:17 PMMar 3
to Nico Weber, Andrew Grieve, cxx
Yay!
Reply all
Reply to author
Forward
0 new messages