Date: Fri, 8 May 2026 23:04:44 +0200
> In theory, the compiler could make that transformation under as-if. If
the class has no friends and it can see all of the members in the current
translation unit, it could elect to inline all the private member
functions, because they can't be called from elsewhere.
I think I see what you mean. If we could express our intentions better
("this function is *definitely not* part of the public interface of the
class") then that would allow more aggressive or just more consistent
optimizations (both runtime and compilation due to less exported symbols).
I don't know much about compilers and linkers and optimization, but this
sounds like something worth looking into.
Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> ezt írta
(időpont: 2026. máj. 8., Pén 20:25):
> On Friday, 8 May 2026 09:19:20 Pacific Daylight Time Máté Ték via
> Std-Proposals
> wrote:
> > > In fact, I'd welcome a discussion on whether private functions could
> have
> >
> > internal linkage, whether they are private extensions or not, so the
> symbol
> > table can be reduced and calls can become simpler and non-interceptible.
> >
> > I don't think we can do anything about 'classic' private functions having
> > external linkage due to this little trick:
> >
> > class MyClass {
> > MY_UNIT_TEST_FRIEND_DECLARATION;
> > };
> >
> > I don't have evidence, but I have a feeling that this pattern alone is
> too
> > widespread to break.
> >
> > Or did you have something else in mind?
>
> Yes. I didn't mean to change existing code. I meant adding an opt-in
> solution.
>
> In theory, the compiler could make that transformation under as-if. If the
> class has no friends and it can see all of the members in the current
> translation unit, it could elect to inline all the private member
> functions,
> because they can't be called from elsewhere.
>
> In fact, I think I really meant "inline" more than "static" here. That
> would
> at least solve the problem that the "static" keyword itself is overloaded
> for
> member functions. This also shows it is possible right now, by explicitly
> adding "inline", as in https://diff.godbolt.org/z/nWrWzzGo9, and that
> this can
> be submitted as a QoI for the generic case.
>
> But I want a more generic solution.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
the class has no friends and it can see all of the members in the current
translation unit, it could elect to inline all the private member
functions, because they can't be called from elsewhere.
I think I see what you mean. If we could express our intentions better
("this function is *definitely not* part of the public interface of the
class") then that would allow more aggressive or just more consistent
optimizations (both runtime and compilation due to less exported symbols).
I don't know much about compilers and linkers and optimization, but this
sounds like something worth looking into.
Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> ezt írta
(időpont: 2026. máj. 8., Pén 20:25):
> On Friday, 8 May 2026 09:19:20 Pacific Daylight Time Máté Ték via
> Std-Proposals
> wrote:
> > > In fact, I'd welcome a discussion on whether private functions could
> have
> >
> > internal linkage, whether they are private extensions or not, so the
> symbol
> > table can be reduced and calls can become simpler and non-interceptible.
> >
> > I don't think we can do anything about 'classic' private functions having
> > external linkage due to this little trick:
> >
> > class MyClass {
> > MY_UNIT_TEST_FRIEND_DECLARATION;
> > };
> >
> > I don't have evidence, but I have a feeling that this pattern alone is
> too
> > widespread to break.
> >
> > Or did you have something else in mind?
>
> Yes. I didn't mean to change existing code. I meant adding an opt-in
> solution.
>
> In theory, the compiler could make that transformation under as-if. If the
> class has no friends and it can see all of the members in the current
> translation unit, it could elect to inline all the private member
> functions,
> because they can't be called from elsewhere.
>
> In fact, I think I really meant "inline" more than "static" here. That
> would
> at least solve the problem that the "static" keyword itself is overloaded
> for
> member functions. This also shows it is possible right now, by explicitly
> adding "inline", as in https://diff.godbolt.org/z/nWrWzzGo9, and that
> this can
> be submitted as a QoI for the generic case.
>
> But I want a more generic solution.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-05-08 21:04:58
