Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Issue 1454993003: Add a move constructor and move assignment operator to scoped_ptr. (Closed)

Created:
5 years, 1 month ago by dcheng
Modified:
5 years, 1 month ago
Reviewers:
danakj, vmpstr
CC:
chromium-reviews, gavinp+memory_chromium.org, vmpstr+watch_chromium.org, Nico
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add a move constructor and move assignment operator to scoped_ptr. Previously, scoped_ptr only had a conversion constructor with a scoped_ptr<U, E> rvalue reference argument. Since this isn't an actual move constructor, this prevented clang's pessimizing move warning from trigger on code like this: scoped_ptr<int> F() { scoped_ptr<int> i; return std::move(i); } In addition, the conversion constructor is now disabled if <U, E> are not convertible to <T, D> respectively. This is important so: 1. type_traits like std::is_convertible don't incorrectly treat scoped_ptr<Base> as convertible to scoped_ptr<Derived>. 2. Code like this compiles: void F(scoped_ptr<int>); void F(scoped_ptr<Base>); F(scoped_ptr<Derived>()); For symmetry, scoped_ptr also has a move assignment operator now, and the conversion assignment operator has been updated to match the conditions when the conversion constructor is disabled via SFINAE. BUG=557438 Committed: https://crrev.com/ecdd662b725c21d5536defc8d6be81ed781caa07 Cr-Commit-Position: refs/heads/master@{#360737}

Patch Set 1 #

Patch Set 2 : Add a real move constructor #

Total comments: 5

Patch Set 3 : . #

Patch Set 4 : Add header #

Total comments: 14

Patch Set 5 : Address comments #

Patch Set 6 : More template magic #

Total comments: 4

Patch Set 7 : Moar comments #

Patch Set 8 : Close enough #

Unified diffs Side-by-side diffs Delta from patch set Stats (+69 lines, -25 lines) Patch
M base/memory/scoped_ptr.h View 1 2 3 4 5 6 7 4 chunks +69 lines, -25 lines 0 comments Download

Messages

Total messages: 54 (18 generated)
danakj
https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h#newcode337 base/memory/scoped_ptr.h:337: scoped_ptr(scoped_ptr<U, V>&& other, I wish clang-format did a better ...
5 years, 1 month ago (2015-11-18 23:39:34 UTC) #2
dcheng
Sorry I haven't had more time to hack on this. Are you going to adopt ...
5 years, 1 month ago (2015-11-19 00:23:24 UTC) #3
vmpstr
https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h#newcode339 base/memory/scoped_ptr.h:339: std::is_convertible<typename scoped_ptr<U, V>::Pointer, On 2015/11/19 00:23:24, dcheng wrote: > ...
5 years, 1 month ago (2015-11-19 00:37:19 UTC) #5
dcheng
https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h#newcode339 base/memory/scoped_ptr.h:339: std::is_convertible<typename scoped_ptr<U, V>::Pointer, On 2015/11/19 at 00:37:18, vmpstr wrote: ...
5 years, 1 month ago (2015-11-19 00:38:57 UTC) #6
vmpstr
On 2015/11/19 00:38:57, dcheng wrote: > https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h > File base/memory/scoped_ptr.h (right): > > https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h#newcode339 > ...
5 years, 1 month ago (2015-11-19 00:39:43 UTC) #7
vmpstr
On 2015/11/19 00:39:43, vmpstr wrote: > On 2015/11/19 00:38:57, dcheng wrote: > > https://codereview.chromium.org/1454993003/diff/20001/base/memory/scoped_ptr.h > ...
5 years, 1 month ago (2015-11-19 00:40:43 UTC) #8
vmpstr
On 2015/11/19 00:40:43, vmpstr wrote: > On 2015/11/19 00:39:43, vmpstr wrote: > > On 2015/11/19 ...
5 years, 1 month ago (2015-11-19 01:10:17 UTC) #9
dcheng
Add a move constructor and move assignment operator to scoped_ptr. Previously, scoped_ptr only had a ...
5 years, 1 month ago (2015-11-19 20:43:44 UTC) #10
dcheng
Oops, I thought I was editing the issue description. Please ignore >_<
5 years, 1 month ago (2015-11-19 20:43:57 UTC) #11
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/40001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/40001
5 years, 1 month ago (2015-11-19 20:45:46 UTC) #16
dcheng
OK, this should be ready for review. I've confirmed locally that it warns, but obviously ...
5 years, 1 month ago (2015-11-19 20:49:10 UTC) #20
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/60001
5 years, 1 month ago (2015-11-19 20:49:15 UTC) #21
dcheng
Oh, and I plan on handling scoped_refptr in a separate CL, just to keep things ...
5 years, 1 month ago (2015-11-19 20:50:19 UTC) #22
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: cast_shell_android on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/cast_shell_android/builds/81535) cast_shell_linux on ...
5 years, 1 month ago (2015-11-19 20:59:49 UTC) #24
vmpstr
(driiiive byyyy) https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode268 base/memory/scoped_ptr.h:268: // we <_< https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode326 base/memory/scoped_ptr.h:326: typename = ...
5 years, 1 month ago (2015-11-19 21:00:24 UTC) #25
danakj
https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode268 base/memory/scoped_ptr.h:268: // we wrapping broke https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode285 base/memory/scoped_ptr.h:285: // // ambiguous ...
5 years, 1 month ago (2015-11-19 21:03:36 UTC) #26
dcheng
On 2015/11/19 at 21:00:24, vmpstr wrote: > (driiiive byyyy) > > https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h > File base/memory/scoped_ptr.h ...
5 years, 1 month ago (2015-11-19 21:11:24 UTC) #27
dcheng
https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode268 base/memory/scoped_ptr.h:268: // we On 2015/11/19 at 21:03:36, danakj (behind on ...
5 years, 1 month ago (2015-11-19 21:26:04 UTC) #28
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/100001
5 years, 1 month ago (2015-11-19 21:28:06 UTC) #30
vmpstr
https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode326 base/memory/scoped_ptr.h:326: typename = typename std::enable_if< On 2015/11/19 21:26:04, dcheng wrote: ...
5 years, 1 month ago (2015-11-19 21:28:41 UTC) #31
dcheng
On 2015/11/19 at 21:28:41, vmpstr wrote: > https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h > File base/memory/scoped_ptr.h (right): > > https://codereview.chromium.org/1454993003/diff/60001/base/memory/scoped_ptr.h#newcode326 ...
5 years, 1 month ago (2015-11-19 21:29:09 UTC) #32
danakj
LGTM https://codereview.chromium.org/1454993003/diff/100001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/100001/base/memory/scoped_ptr.h#newcode247 base/memory/scoped_ptr.h:247: typedef T element_type; using here too while you're ...
5 years, 1 month ago (2015-11-19 21:31:11 UTC) #33
dcheng
https://codereview.chromium.org/1454993003/diff/100001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/1454993003/diff/100001/base/memory/scoped_ptr.h#newcode247 base/memory/scoped_ptr.h:247: typedef T element_type; On 2015/11/19 at 21:31:11, danakj (behind ...
5 years, 1 month ago (2015-11-19 21:39:45 UTC) #34
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/110001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/110001
5 years, 1 month ago (2015-11-19 21:42:31 UTC) #37
commit-bot: I haz the power
Try jobs failed on following builders: android_arm64_dbg_recipe on tryserver.chromium.linux (JOB_FAILED, no build URL) android_compile_dbg on ...
5 years, 1 month ago (2015-11-19 22:12:01 UTC) #39
dcheng
So the bots are not a big fan of this change. It looks like std::is_assignable ...
5 years, 1 month ago (2015-11-19 23:01:06 UTC) #40
danakj
On Thu, Nov 19, 2015 at 3:01 PM, <dcheng@chromium.org> wrote: > So the bots are ...
5 years, 1 month ago (2015-11-19 23:03:25 UTC) #41
dcheng
On 2015/11/19 at 23:03:25, danakj wrote: > On Thu, Nov 19, 2015 at 3:01 PM, ...
5 years, 1 month ago (2015-11-20 00:08:24 UTC) #43
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/120001
5 years, 1 month ago (2015-11-20 00:10:48 UTC) #44
danakj
On Thu, Nov 19, 2015 at 4:08 PM, <dcheng@chromium.org> wrote: > On 2015/11/19 at 23:03:25, ...
5 years, 1 month ago (2015-11-20 00:39:09 UTC) #45
dcheng
On 2015/11/20 at 00:39:09, danakj wrote: > On Thu, Nov 19, 2015 at 4:08 PM, ...
5 years, 1 month ago (2015-11-20 01:58:45 UTC) #46
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: ios_dbg_simulator_ninja on tryserver.chromium.mac (JOB_TIMED_OUT, no build URL) ...
5 years, 1 month ago (2015-11-20 02:17:50 UTC) #48
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1454993003/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1454993003/120001
5 years, 1 month ago (2015-11-20 02:27:20 UTC) #51
commit-bot: I haz the power
Committed patchset #8 (id:120001)
5 years, 1 month ago (2015-11-20 04:01:11 UTC) #52
commit-bot: I haz the power
Patchset 8 (id:??) landed as https://crrev.com/ecdd662b725c21d5536defc8d6be81ed781caa07 Cr-Commit-Position: refs/heads/master@{#360737}
5 years, 1 month ago (2015-11-20 04:01:45 UTC) #53
danakj
5 years, 1 month ago (2015-11-20 18:39:05 UTC) #54
Message was sent while issue was closed.
On Thu, Nov 19, 2015 at 5:58 PM, <dcheng@chromium.org> wrote:

> On 2015/11/20 at 00:39:09, danakj wrote:
>
>> On Thu, Nov 19, 2015 at 4:08 PM, <dcheng@chromium.org> wrote:
>>
>
> > On 2015/11/19 at 23:03:25, danakj wrote:
>> >
>> >> On Thu, Nov 19, 2015 at 3:01 PM, <dcheng@chromium.org> wrote:
>> >>
>> >
>> > > So the bots are not a big fan of this change. It looks like
>> >> > std::is_assignable
>> >> > is in the same bucket as std::underlying_type: it just doesn't work
>> on
>> >> > lots of
>> >> > our platforms =(
>> >> >
>> >> > I'll send an update to the C++11 style guide. In the mean time, maybe
>> >> > is_convertible<> is a good enough approximation?
>> >> >
>> >>
>> >
>> > Uh.. it's more strict right? It means if operator= would have worked, it
>> >> might not know. But things that are implicitly convertible can always
>> be
>> >> assigned. It seems okay for now.
>> >>
>> >
>> > --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >>
>> > "Chromium-reviews" group.
>> >
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> an
>> >>
>> > email to chromium-reviews+unsubscribe@chromium.org.
>> >
>> >
>> > I uploaded a version that uses is_convertible for now. I don't think
>> > is_convertible implies is_assignable though: you could write a class
>> such
>> > that
>> > it is convertible but not assignable.
>> >
>>
>
> Really? But wouldn't it just implicitly convert and bind to that operator=?
>>
>
> dcheng@truffula:~/src/chrome/src$
> third_party/llvm-build/Release+Asserts/bin/clang++ -std=c++11  test7.cc
> dcheng@truffula:~/src/chrome/src$ cat test7.cc
> #include <iostream>
> #include <memory>
> #include <type_traits>
>
> struct B {
> };
>
> struct A {
>   A(const B&) {}
>   A(const A&) {}
>   A& operator=(const A&) = delete;
> };
>
> int main() {
>   std::cout << std::boolalpha;
>   std::cout << "std::is_convertible<B, A>: " << std::is_convertible<B,
> A>::value
>             << "\n";
>   std::cout << "std::is_assignable<A, B>: " << std::is_assignable<A,
> B>::value
>             << "\n";
> }
> dcheng@truffula:~/src/chrome/src$ ./a.out
> std::is_convertible<B, A>: true
> std::is_assignable<A, B>: false


Ahh = delete, so cheating. Good thinking :)



>
>
>
>
> >
>> > Also, I was curious how libstdc++4.6 deals with this. The answer? It
>> > doesn't!
>> >
>> > It also uses the typename = typename std::enable_if<> construct that
>> > previous
>> > versions of this CL used.
>> >
>>
>
> Fun. :) Then that seems extra okay. And motivating to use the std lib so we
>> can blame them? :P
>>
>
> --
>> You received this message because you are subscribed to the Google Groups
>>
> "Chromium-reviews" group.
>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>
> email to chromium-reviews+unsubscribe@chromium.org.
>
>
> https://codereview.chromium.org/1454993003/
>

-- 
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.

Powered by Google App Engine
This is Rietveld 408576698