Discuss Online
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
lysdexic@programming.devM to C++@programming.devEnglish · 2 years ago

On harmful overuse of std::move - The Old New Thing

devblogs.microsoft.com

external-link
message-square
22
link
fedilink
29
external-link

On harmful overuse of std::move - The Old New Thing

devblogs.microsoft.com

lysdexic@programming.devM to C++@programming.devEnglish · 2 years ago
message-square
22
link
fedilink
Initial excitement leads to overuse.
  • QuadriLiteral@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    2 years ago

    I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

    • Dani (:cxx: modules addict)@hachyderm.io
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      @QuadriLiteral @lysdexic We’ve been looking at a paper just recently in Kona, where the author proposed to not penalize “unfortunate” uses of std::move. I think this is user friendly and you might imagine what I’ve been voting for.

      • QuadriLiteral@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        That sounds great!

    • lysdexic@programming.devOPM
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

      These std::move invocations are harmless, as they only cast objects to their rvalue reference.

      The destructive bit takes place in the type they are assigned to, as it invokes either a move constructor or a move assignment operator, and calling those implies that the object you just passed to std::move will be invalidated after the call and should not be used subsequently.

      • QuadriLiteral@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        I mean harmless in a way that using std::move on the return type doesn’t prevent RVO?

      • Dani (:cxx: modules addict)@hachyderm.io
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        @lysdexic @QuadriLiteral Eh, no. Really. Changing the value category disables RVO

        • lysdexic@programming.devOPM
          link
          fedilink
          English
          arrow-up
          1
          ·
          2 years ago

          RVO

          I recommend you read the thread.

          • Dani (:cxx: modules addict)@hachyderm.io
            link
            fedilink
            arrow-up
            1
            ·
            2 years ago

            @lysdexic I did.

            • lysdexic@programming.devOPM
              link
              fedilink
              English
              arrow-up
              1
              ·
              2 years ago

              It doesn’t look like it, otherwise you’d be aware that the whole point of this submission is that casting return values with std::move disables RVO.

              • Dani (:cxx: modules addict)@hachyderm.io
                link
                fedilink
                arrow-up
                1
                ·
                2 years ago

                @lysdexic You claimed otherwise:
                "
                These std::move invocations are harmless, as they only cast objects to their rvalue reference.
                "
                If you were right, we wouldn’t have the motivation to look at this in EWG.

                • lysdexic@programming.devOPM
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  2 years ago

                  If you were right, we wouldn’t have the motivation to look at this in EWG.

                  I am right. Not benefiting from RVO does not mean you’re harming anyone.

                  Again, I recommend you read the submission and also the discussion.

C++@programming.dev

cpp@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !cpp@programming.dev

The center for all discussion and news regarding C++.

Rules

  • Respect instance rules.
  • Don’t be a jerk.
  • Please keep all posts related to C++.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 2 users / day
  • 1 user / week
  • 69 users / month
  • 233 users / 6 months
  • 4 local subscribers
  • 2.07K subscribers
  • 281 Posts
  • 492 Comments
  • Modlog
  • mods:
  • Nihili0@programming.dev
  • lysdexic@programming.dev
  • BE: 0.19.12
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org