Giter VIP home page Giter VIP logo

Comments (5)

andreasfertig avatar andreasfertig commented on May 27, 2024

Hello @amutamil,

thanks for your feedback!

Without a minimal working example, this is tough to say. In a quick example, I drafted (https://cppinsights.io/s/f4c0dc68), the transformation works as expected.

I'm happy to look at your example.

Andreas

from cppinsights.

amutamil avatar amutamil commented on May 27, 2024

Hello @andreasfertig ,

please refer this example https://cppinsights.io/s/647ccf1d,

Regards,
Amutamil E

from cppinsights.

andreasfertig avatar andreasfertig commented on May 27, 2024

Hello @amutamil,

thanks for sharing the code.

Please have a close look at our two different versions. My struct test comes without a user-provided destructor. As a result, you can see that test, in my case, uses a compiler-provided move constructor (line 5 in the transformed output). Due to the destructor's presence in your example, only a compiler-provided copy constructor exists. This is why there is a cast around the std::move, which adds const.

In short, C++ Insights does what it is supposed to do: show you what's actually happening.

I wrote about this in one of my blog posts: andreasfertig.blog/2023/11/why-you-shouldnt-provide-an-empty-destructor/.

Andreas

from cppinsights.

amutamil avatar amutamil commented on May 27, 2024

Hello @andreasfertig,

Sorry if I deviated you from the real bug. I saw that video, from that video only I found this bug,

the real question is after C++ insights translate move into casting also why do we have std::move still being part of the translated version

test(static_cast<const test &&>(std::move(t))); here in last still why we have std::move(t). This can't be just test(static_cast<const test &&>(t));?

Amutamil E

from cppinsights.

andreasfertig avatar andreasfertig commented on May 27, 2024

Hello @amutamil,

the real question is after C++ insights translate move into casting also why do we have std::move still being part of the translated version

C++ Insights doesn't translate move. I leave STL functions as they are. One reason why I'm not keen to add special code for std::variant. Whatever these functions internally do is part of their implementation.

test(static_cast<const test &&>(std::move(t))); here in last still why we have std::move(t). This can't be just test(static_cast<const test &&>(t));?

As I said above, std::move is not transformed. The cast you see is there because your code is not doing what you expect it to do. The cast C++ Insights shows you is adding const to the rvalue reference the inner std::move returns. If C++ Insights would transform move to a cast, your code would look like this:

test(static_cast<const test &&>(static_cast<test&&>(t)));

Andreas

from cppinsights.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.