Remix.run Logo
bluGill 2 hours ago

The simple cases are simple. However the complex cases get hard.

    mytype foo() {
       mytype one;
       ...
       if(something) {
          mytype two;
          ...
          return two;
       }
    return one;
    }
Is going to be much harder because you don't know are compile time which is returned and so cannot construct the one you return in the correct place. That is just off the top of my head, I'm not a compiler writer, I'm sure they have figured out the simple versions of the above, but you can start to see the complex versions that they can't.
leni536 19 minutes ago | parent [-]

That one is not too hard either. `one` simply can't be NRVO'd as there is a runtime path in scope of it that doesn't return it. `two` can be (unless you hide some other return within ...).