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:40:44 -0700
On Tuesday, 28 April 2026 23:58:46 Pacific Daylight Time André Offringa via Std-
Proposals wrote:
> So if in one translation unit Foo is instantiated without seeing A(int)
> and in another
> Foo is instantiated with seeing A(int), it would be ill-formed (IFNDR).
>
> If you were thinking of a different problem, could you give an example?

That was it. This would be ODR and thus would be IFNDR.

The question is whether we should allow this syntax change that can create a
new ODR violation possibility.

> I think this problem is similar as that is already the case with free
> functions, isn't it?

Not your example: https://diff.godbolt.org/z/eqnK5TfEW. Expansion only applies
to functions that had been visible at the point of definition of the template,
not the instantiation. Even if ADL.

It's different if the declarations change above the definition, which then
applies to non-templates too: https://diff.godbolt.org/z/8WsfT9TdK

Classes are different because the full class is parsed as one block before
expansion starts. That's what allows you to call member functions declared
below the body of the one being parsed. So if you could add to the class,
would that change?

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

Received on 2026-04-29 16:40:55