[libcxx-commits] [PATCH] D68805: [libcxx] Remove shared_ptr::make_shared
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 16 09:13:43 PDT 2019
ldionne added inline comments.
================
Comment at: libcxx/include/memory:3876
+ static shared_ptr<_Tp>
+ __create_with_cntrl_block(_Yp* __p, _CntrlBlk* __cntrl)
+ {
----------------
Can we call this `__create_with_control_block` instead? We're not saving many characters.
================
Comment at: libcxx/include/memory:4421
+
+ return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(),
+ __hold2.release());
----------------
This just jumped in my face -- it's obvious now.
We're calling a function `f(p.get()->foobar(), p.release())` where `p` is a `unique_ptr`. If the second argument (`p.release()`) is evaluated before the first one, `p.get()` will be `nullptr` and we'll dereference that, causing the segfault. @phosek must have been testing on a target where the compiler evaluates arguments from right to left.
I think we pinned down the order of evaluation in C++20 (I'm not sure whether it actually got in), but it's definitely a problem for earlier standards anyway.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68805/new/
https://reviews.llvm.org/D68805
More information about the libcxx-commits
mailing list