C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Translation-unit-local functions that access private class fields

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 21 Jun 2026 12:24:57 -0400
On Sunday, 21 June 2026 10:20:56 Eastern Daylight Time Rhidian De Wit wrote:
> I think the original path of PEMs being tied to 1 TU is more natural to the
> idea of a private method. In that regard, I also believe it to be then only
> natural for a PEM to have internal linkage. PEMs can be defined in a header
> and included in a TU, so long the PEM is only defined & used in 1 TU.
>
> Future work for PEMs should be to have Protected Extension Methods, and
> moreso, Public Extension Methods.
>
> Those 2 should have external linkage and are allowed to be shared across
> TUs, unlike PEMs, which cannot be shared at all.

Except that if you were to return a pointer to a private extension method from
a public/protected one, it is shared and cannot be internal linkage.

I ask you to consider if you are painting yourself in a corner by insisting on
internal linkage, in addition to creating new rules that add to the
complexity, all of this for little to no gain. LTO solves most of the problems
of unnecessarily emitting methods.

Not all. For example, if a class is exported and has friends, the compiler may
have no choice but to emit all non-inline methods, even if it has inlined
everything, and even in LTO mode. But if this problem needs solving (and I'd
argue it does), it applies to current code too and therefore deserves a
solution independent of the private extension methods.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-06-21 16:25:11