C++ Logo


Advanced search

Re: [std-proposals] this return type

From: Jan Schultke <janschultke_at_[hidden]>
Date: Sat, 8 Apr 2023 21:51:37 +0200
It's not a missed optimization. The compiler can know that we are
dealing with a B&, and that B& must be returned from f1(), f2(), f3(),
but this is not helpful.

We are still making virtual calls to do_f1(), do_f2(), do_f3(). If we
could magically devirtualize any call by going through a member
function that has "return *this;" in it, it would totally break

However, there is something that does look like a missed optimization
here: https://www.godbolt.org/z/3Kc8dnMMj

going through a non-virtual member function seems to prevent
de-virtualization for seemingly no reason.

Received on 2023-04-08 19:51:49