C++ Logo


Advanced search

Re: [std-proposals] copy constructor of std::vector

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 13 Jun 2023 10:12:59 -0700
On Tuesday, 13 June 2023 08:19:56 PDT Federico Kircheis via Std-Proposals
> > This will fix nothing, as the vector needs to behave the same
> > whether the type is forward declared or not. You do not control it
> > as in some TU it will use forward declared type and in others it will not.
> > You will get multiple ODR problems where you check this condition.
> I am not sure I get your point.
> The behavior of vector would not change, as "auto s2 = s1;" would
> continue not to compile.

You didn't get the point.

There's an ODR violation because the expansion differed when it was forward-
declared versus when it wasn't.

std::is_copy_assignable_v<vector<ForwardDeclared>> necessarily has to be true,
because it can't know whether ForwardDeclared is copy-assignable or not. That
means code in one TU will make use of that true, whereas in another TU it
might already be false and go down a different code path.

Plus, there's the case when ForwardDeclared is declared in this TU, but later
than this point here. So the value changes from true to false within one TU,
but only with some compilers (the Standard does allow reaching the end of the
TU before beginning the template instantiation and I know of one compiler that
uses that).

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-06-13 17:13:01