Date: Fri, 08 May 2026 11:25:11 -0700
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.
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.
Received on 2026-05-08 18:25:22
