Remove paragraph on return std::move with implicit conversion [website : main]

21 views
Skip to first unread message

Martin Bidlingmaier (Gerrit)

unread,
Jul 27, 2022, 10:46:40 AM7/27/22
to c...@chromium.org

Attention is currently required from: Martin Bidlingmaier.

Martin Bidlingmaier has uploaded this change for review.

View Change

Remove paragraph on return std::move with implicit conversion

Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
---
M site/rvalue-references/index.md
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/site/rvalue-references/index.md b/site/rvalue-references/index.md
index 8a7edb7..a9609e3 100644
--- a/site/rvalue-references/index.md
+++ b/site/rvalue-references/index.md
@@ -456,23 +456,6 @@
a previous chromium-dev thread about this in the context of scoped_ptr:
[link](https://groups.google.com/a/chromium.org/d/msg/chromium-dev/ICA3hiR4Z3A/Bi_ec46cAQAJ).

-However, if the types of the variable and the return type do not match exactly,
-then you will have to use std::move() in order to convert without creating an
-extra temporary.
-
-std::unique_ptr<MyType> MakeMyType()
-
-{
-
-std::unique_ptr<ChildClassOfMyType> ptr;
-
-// This call to std::move() is needed to convert from a pointer-to-the
-
-// child class to a pointer-to-the parent.
-
-return std::move(ptr);
-}
-
Similarly do not use move() on the return value from calling a function. You
already have an rvalue, so casting it there adds no value, only noise.


To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 1
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-MessageType: newchange

Martin Bidlingmaier (Gerrit)

unread,
Jul 27, 2022, 10:46:46 AM7/27/22
to c...@chromium.org, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

Patch set 1:Commit-Queue +1

View Change

1 comment:

  • Patchset:

    • Patch Set #1:

      Hi everybody,

      Can you have a look at this change about our c++ style with regards to move semantics? It's about situations such as this one:

      ```
      struct A{};
      struct B : A {};
      std::unique_ptr<A> foo() {
      auto result = std::make_unique<B>();
      // Implicitly convert rvalue of unique_ptr<B> to unique_ptr<A>.
      return std::move(result);
      }
      ```

      As far as I know, compilers must treat a variable as rvalue when it is returned if it is local or a function parameter.  Thus the `std::move` here is superfluous. Indeed, both clang and gcc compile the above snippet without the `std::move`.

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 1
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-Comment-Date: Wed, 27 Jul 2022 14:46:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Nico Weber (Gerrit)

unread,
Jul 27, 2022, 10:51:23 AM7/27/22
to Martin Bidlingmaier, c...@chromium.org, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

Patch set 1:Code-Review +1

View Change

1 comment:

  • File site/rvalue-references/index.md:

    • Patch Set #1, Line 467: std::unique_ptr&lt;ChildClassOfMyType&gt; ptr;

      I think the point here was that the function return ChildClassOfMyType from a function returning MyType.

      Before C++14 (?), this did need the explicit move, and I think this is a remnant from then. It's true that this is now no longer needed.

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 1
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Comment-Date: Wed, 27 Jul 2022 14:51:16 +0000

Martin Bidlingmaier (Gerrit)

unread,
Jul 28, 2022, 4:58:50 AM7/28/22
to Elly Fong-Jones, c...@chromium.org, Nico Weber

Attention is currently required from: Elly Fong-Jones.

Martin Bidlingmaier would like Elly Fong-Jones to review this change.

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 1
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Attention: Elly Fong-Jones <elly...@chromium.org>
Gerrit-MessageType: newchange

Martin Bidlingmaier (Gerrit)

unread,
Jul 28, 2022, 5:01:02 AM7/28/22
to c...@chromium.org

Attention is currently required from: Elly Fong-Jones.

Martin Bidlingmaier uploaded patch set #2 to this change.

View Change

Remove paragraph on return std::move with implicit conversion

The std::move is no longer needed in these situations.


Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
---
M site/rvalue-references/index.md
1 file changed, 11 insertions(+), 17 deletions(-)

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 2
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Attention: Elly Fong-Jones <elly...@chromium.org>
Gerrit-MessageType: newpatchset

Martin Bidlingmaier (Gerrit)

unread,
Jul 28, 2022, 5:35:52 AM7/28/22
to c...@chromium.org, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Elly Fong-Jones.

View Change

1 comment:

  • File site/rvalue-references/index.md:

    • I think the point here was that the function return ChildClassOfMyType from a function returning MyT […]

      Ack

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 3
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Attention: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Comment-Date: Thu, 28 Jul 2022 09:35:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Weber <tha...@chromium.org>
Gerrit-MessageType: comment

Martin Bidlingmaier (Gerrit)

unread,
Jul 28, 2022, 5:38:33 AM7/28/22
to c...@chromium.org

Attention is currently required from: Elly Fong-Jones, Martin Bidlingmaier.

Martin Bidlingmaier uploaded patch set #5 to this change.

View Change

The following approvals got outdated and were removed: Commit-Queue+1 by Martin Bidlingmaier

Remove paragraph on return std::move with implicit conversion

The std::move is no longer needed in these situations.
Drive-by: Replace unique_ptr<...>(new ...) with make_unique in code snippet.

Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
---
M site/developers/smart-pointer-guidelines/index.md
M site/rvalue-references/index.md
2 files changed, 16 insertions(+), 24 deletions(-)

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 5
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Attention: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-MessageType: newpatchset

Martin Bidlingmaier (Gerrit)

unread,
Jul 28, 2022, 5:44:44 AM7/28/22
to c...@chromium.org

Attention is currently required from: Elly Fong-Jones, Martin Bidlingmaier.

Martin Bidlingmaier uploaded patch set #6 to this change.

View Change

Remove paragraph on return std::move with implicit conversion


The std::move is no longer needed in these situations.
Drive-by: Replace unique_ptr<...>(new ...) with make_unique in code snippet.

Bug: b/240531273

Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
---
M site/developers/smart-pointer-guidelines/index.md
M site/rvalue-references/index.md
2 files changed, 17 insertions(+), 24 deletions(-)

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6

Elly Fong-Jones (Gerrit)

unread,
Jul 28, 2022, 11:34:25 AM7/28/22
to Martin Bidlingmaier, c...@chromium.org, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

Patch set 6:Code-Review +1

View Change

1 comment:

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-Comment-Date: Thu, 28 Jul 2022 15:34:17 +0000

K. Moon (Gerrit)

unread,
Jul 28, 2022, 11:48:33 AM7/28/22
to Martin Bidlingmaier, c...@chromium.org, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

View Change

1 comment:

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-CC: K. Moon <km...@chromium.org>
Gerrit-Comment-Date: Thu, 28 Jul 2022 15:48:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

K. Moon (Gerrit)

unread,
Jul 28, 2022, 12:02:38 PM7/28/22
to Martin Bidlingmaier, c...@chromium.org, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

View Change

1 comment:

  • Patchset:

    • Patch Set #6:

      It's subtle, and I had to double-check this, but we need to distinguish between three cases here: […]

      For reference, I played around with the different cases in Compiler Explorer:
      https://godbolt.org/z/bbdnM5rhh

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-CC: K. Moon <km...@chromium.org>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-Comment-Date: Thu, 28 Jul 2022 16:02:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: K. Moon <km...@chromium.org>
Gerrit-MessageType: comment

Nico Weber (Gerrit)

unread,
Jul 28, 2022, 3:45:45 PM7/28/22
to Martin Bidlingmaier, c...@chromium.org, K. Moon, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: K. Moon, Martin Bidlingmaier.

Patch set 6:Code-Review +1

View Change

1 comment:

  • Patchset:

    • Patch Set #6:

      For reference, I played around with the different cases in Compiler Explorer: […]

      The interesting bit here is that the local is a subclass of the return type, no? ie https://godbolt.org/z/ea31TqcG7

      I thought this would be affected by https://cplusplus.github.io/CWG/issues/1579.html and hence c++14 is what makes the difference, but apparently clang trunk doesn't consider the std::move() pessimizing even in c++11.

      But it works without the move too.

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-CC: K. Moon <km...@chromium.org>
Gerrit-Attention: K. Moon <km...@chromium.org>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-Comment-Date: Thu, 28 Jul 2022 19:45:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

K. Moon (Gerrit)

unread,
Jul 28, 2022, 3:58:33 PM7/28/22
to Martin Bidlingmaier, c...@chromium.org, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Attention is currently required from: Martin Bidlingmaier.

View Change

1 comment:

  • Patchset:

    • Patch Set #6:

      The interesting bit here is that the local is a subclass of the return type, no? ie https://godbolt. […]

      Agreed; it seems like more could be done here, but the change is fine as-is.

To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: main
Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
Gerrit-Change-Number: 3788415
Gerrit-PatchSet: 6
Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-CC: K. Moon <km...@chromium.org>
Gerrit-Attention: Martin Bidlingmaier <mb...@google.com>
Gerrit-Comment-Date: Thu, 28 Jul 2022 19:58:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: K. Moon <km...@chromium.org>

Martin Bidlingmaier (Gerrit)

unread,
Jul 29, 2022, 7:25:19 AM7/29/22
to c...@chromium.org, K. Moon, Elly Fong-Jones, Nico Weber, Tricium, chromium-we...@luci-project-accounts.iam.gserviceaccount.com

Patch set 6:Commit-Queue +2

View Change

    To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: website
    Gerrit-Branch: main
    Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
    Gerrit-Change-Number: 3788415
    Gerrit-PatchSet: 6
    Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
    Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
    Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-CC: K. Moon <km...@chromium.org>
    Gerrit-Comment-Date: Fri, 29 Jul 2022 11:25:11 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    chromium-website-scoped@luci-project-accounts.iam.gserviceaccount.com (Gerrit)

    unread,
    Jul 29, 2022, 7:28:41 AM7/29/22
    to Martin Bidlingmaier, c...@chromium.org, K. Moon, Elly Fong-Jones, Nico Weber, Tricium

    chromium-we...@luci-project-accounts.iam.gserviceaccount.com submitted this change.

    View Change


    Approvals: Elly Fong-Jones: Looks good to me Nico Weber: Looks good to me Martin Bidlingmaier: Commit
    Remove paragraph on return std::move with implicit conversion

    The std::move is no longer needed in these situations.
    Drive-by: Replace unique_ptr<...>(new ...) with make_unique in code snippet.

    Bug: b/240531273
    Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
    Reviewed-on: https://chromium-review.googlesource.com/c/website/+/3788415
    Reviewed-by: Nico Weber <tha...@chromium.org>
    Commit-Queue: Martin Bidlingmaier <mb...@google.com>
    Reviewed-by: Elly Fong-Jones <elly...@chromium.org>

    ---
    M site/developers/smart-pointer-guidelines/index.md
    M site/rvalue-references/index.md
    2 files changed, 21 insertions(+), 24 deletions(-)


    To view, visit change 3788415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: website
    Gerrit-Branch: main
    Gerrit-Change-Id: I17d34b011eedd906552a6bf8583a021e9071928a
    Gerrit-Change-Number: 3788415
    Gerrit-PatchSet: 7
    Gerrit-Owner: Martin Bidlingmaier <mb...@google.com>
    Gerrit-Reviewer: Elly Fong-Jones <elly...@chromium.org>
    Gerrit-Reviewer: Martin Bidlingmaier <mb...@google.com>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-CC: K. Moon <km...@chromium.org>
    Gerrit-MessageType: merged
    Reply all
    Reply to author
    Forward
    0 new messages