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: Wed, 29 Apr 2026 09:48:04 -0700
On Wednesday, 29 April 2026 02:51:20 Pacific Daylight Time Máté Ték via Std-
Proposals wrote:
> So what if we try to follow this principle as closely as possible?
> - All TUs should agree on public/protected members -- we don't plan to
> break this.
> - TUs can be denied from knowing the private member methods of a class (on
> a need-to-know basis)... -- we all seem to agree on this so far --
> - ..., but those that need to know should all agree on the private
> interface as well. (?)

As you yourself said, I wouldn't tie this to TUs.

I would say that all member functions of a class should agree on the private
function and static data members, regardless of which TU they come from.

This easily expands to protected: all members of this class and any derived
ones must agree on the privates and protecteds.

Failure to obey this rule would be ODR violation.

All non-static data members must be visible to everyone, no exceptions.

But see other email for another shortfall.

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

Received on 2026-04-29 16:48:08