C++ Logo

std-proposals

Advanced search

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

From: Chris Blume (ProgramMax) <"Chris>
Date: Sun, 22 Feb 2026 16:33:44 -0500
Hello,

I am following step 1, "Float the idea" from How to submit a proposal
<https://isocpp.org/std/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(); };

When the default initializer is not used, the type is still deduced from it.


I believe this aligns nicely with the rest of the language. For example:
void Foo() {
  auto bar = baz(); // Type deduced, value set
  ...
  auto bar2; // Error, cannot deduce type
  // Just like how this would not work without a default member initializer.
  ...
  auto bar3 = baz();
  bar3 = 2; // Type remains, different value set
  // This is similar to how a non-default member initialization would work.
  // Granted, this is a bit of a stretch since baz() is still called here.
But I think the example works well enough.
}


Thank you for your consideration. I'm open to thoughts & feedback.

Received on 2026-02-22 21:34:01