I have previously thought about the idea of the operator() auto supplied return type and implied return value (IF and only iF omitted) as your original idea started with. The implied return value (aka *this) (IFF omitted) would be just like main() having the implied return 0; (IFF omitted). I would need to hear other people's arguments pro or con but am open to it. There might be a hidden gotcha that I have not thought of.
[edit: just found the funniest thing,
You can not do:
struct A {
virtual auto operator++() { return *this; }
//"
error: virtual function cannot have deduced return type"
//or
virtual decltype(*this) operator++() { return *this; }
//
error: invalid use of 'this' at top level};
but you can use auto and decltype(*this) if you use the training return type. Bonus: the return type honors the function constness like you wanted.
struct A {
virtual auto operator++() const -> decltype(*this) { return *this; }
virtual auto operator++(int) -> decltype(*this) { return *this; }
};
so half of it can be done, the compiler knows. Now to just make it implied.
end edit]
My suggestion is just forget using the argument of an optimization and just keep the original idea,
operator() auto supplied return type and
operator() implied return value. I think that anything else is just too problematic and confusing and confuses the issue.
Typically the standards committee does not like suggesting or requiring optimizations. The compiler implementers can optimize it away, if they like, if they don't have an issue with it.
Your idea also ONLY works IF you can see the internals of those methods. The implementation might not be in the header and might return something other than you expected.
Your idea about presuming the address does not change would fail with multiple inheritance even though you're still dealing with the same object just a different base or the derived type itself, the address is potentially different.