Date: Fri, 4 Sep 2026 12:00:13 +0200
On Fri, Sep 4, 2026 at 7:38 AM Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> On Fri, Sep 4, 2026 at 5:55 AM Simon Schröder wrote:
> >
> > I would claim that this feature would be useful.
> > However, it does not follow the zero cost abstraction principle.
>
> There's zero overhead in marking a constructor as [[must_new]].
>
That is correct. My comment was mostly on std::came_from_new(). There are
design patterns to enforce [[must_new]]: make the constructors private and
use a factory function that internally uses 'new'. BTW, in Qt I don't
always use 'new'. 'new' is only necessary when the QObject also gets a
parent (and the parent is destroyed before this object). E.g., a QDialog I
usually create as a stack variable. The main window is another one I create
on the stack. In this case I specifically don't want constructors to be
marked as [[must_new]]. I guess the same would hold for wxWidgets. And if
these are the only use cases, I'd rather have libraries follow in the
footsteps of Wt instead of standardizing new C++ features to support an
outdated design pattern from the 90's. It's now 2026 and we had smart
pointers for 15 years (though, the new std::polymorphic might be even
better in these cases).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
<std-proposals_at_[hidden]> wrote:
> On Fri, Sep 4, 2026 at 5:55 AM Simon Schröder wrote:
> >
> > I would claim that this feature would be useful.
> > However, it does not follow the zero cost abstraction principle.
>
> There's zero overhead in marking a constructor as [[must_new]].
>
That is correct. My comment was mostly on std::came_from_new(). There are
design patterns to enforce [[must_new]]: make the constructors private and
use a factory function that internally uses 'new'. BTW, in Qt I don't
always use 'new'. 'new' is only necessary when the QObject also gets a
parent (and the parent is destroyed before this object). E.g., a QDialog I
usually create as a stack variable. The main window is another one I create
on the stack. In this case I specifically don't want constructors to be
marked as [[must_new]]. I guess the same would hold for wxWidgets. And if
these are the only use cases, I'd rather have libraries follow in the
footsteps of Wt instead of standardizing new C++ features to support an
outdated design pattern from the 90's. It's now 2026 and we had smart
pointers for 15 years (though, the new std::polymorphic might be even
better in these cases).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-09-04 10:00:57
