C++ Logo

std-proposals

Advanced search

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

From: Chris Blume (ProgramMax) <"Chris>
Date: Sun, 22 Feb 2026 18:05:05 -0500
Thank you.
The summary was very helpful. Especially Daveed's example
of decltype(<expr1>) x = <expr2>; where the expressions see a different
completeness of the class, like you pointed out.

A search for "auto data members" didn't turn up good results in the first
few pages. Sorry for beating a dead horse there.




On Sun, Feb 22, 2026 at 4:41 PM Ville Voutilainen <
ville.voutilainen_at_[hidden]> wrote:

> 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 23:05:17