C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Auto-deduction of return value for derived functions.

From: Ivan Lazaric <ivan.lazaric1_at_[hidden]>
Date: Sat, 14 Feb 2026 04:46:06 +0100
What if the return type was a reference?
Someone reading Derived::getList() implementation might naively think
the function returns a plain value due to auto return
Obviously they should see override then realize they need to look at
base class member function declaration,
but the point is, it's making seeing auto as return a bit less clear.
Maybe not a big deal since we can do `auto fn() -> stuff;`

On Sat, Feb 14, 2026 at 4:32 AM Renji Panicker via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi all,
>
> I am floating this idea here to get some early feedback and suggestions before I work on it further.
>
> In C++, the overriding function of a base class virtual function should be permitted to specify 'auto' as its return type.
>
> Example:
> class Base {
> virtual std::vector<std::string> getList() = 0;
> }:
>
> class Derived : public Base {
> virtual auto getList() override {
> // do something
> }
> }:
>
> Per existing C++ rules:
> 1. The return type does not contribute to the function signature.
> 2. The return type of the derived function must necessarily always match that of the base class virtual function.
>
> So we can mark it as ‘auto’ and let the compiler infer the type from the base class virtual function.
>
> This promotes stronger adherence to the DRY (Don’t Repeat Yourself) principle.
>
> Let me know what you think of this.
>
> Regards,
> -/renji
> https://linkedin.com/in/renjipanicker
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-02-14 03:46:21