C++ Logo

std-proposals

Advanced search

Re: [std-proposals] auto member type deduction from default initializer

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sun, 22 Feb 2026 23:41:43 +0200
On Sun, 22 Feb 2026 at 23:34, Chris Blume (ProgramMax) via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> Hello,
>
> I am following step 1, "Float the idea" from How to submit a proposal and looking for interest & feedback.
>
>
> As a quality of life benefit, I propose allowing auto type deduction for members that are given a default initializer:
> class Foo{ auto bar_ = baz(); };
>
> It would be the same as:
> class Foo{ decltype(baz()) bar_ = baz(); };

..except that it isn't, because the former evaluates baz() in a
complete-class context and then deduces the type of Foo::bar_
from it, whereas the latter evaluates baz() in an incomplete-class
context and nails that down as the type of Foo::bar_ regardless
of what that thing does in the complete-class context.

More fun thoughts at
https://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3897.html

Received on 2026-02-22 21:42:00