Anonymous records with typedef names for linkage
John McCall
rjmccall at apple.com
Wed Jan 29 15:14:20 PST 2014
On Jan 29, 2014, at 7:54 AM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
> On 29 January 2014 04:20, John McCall <rjmccall at apple.com> wrote:
>> (*) This is, of course, ill-formed prior to C++11 because the type doesn’t have external linkage, except that it isn’t ill-formed if the anonymous struct acquires a typedef name for linkage purposes.
>>
>> As far as I can tell, this is not technically a language problem, because there is nothing in the language which requires us to compute linkage at a specific point during the processing of a file. For example, C++03 requires us to check whether a template argument has external linkage, but there’s nothing forcing us to check that while processing the template argument; we could delay the check indefinitely, even to the end of the translation unit, as long as we eventually diagnose it. But I’m reluctant to actually propose that we pursue an approach that delays all linkage computations that might involve a still-being-defined anonymous declaration until that declaration is complete; that seems like a very brittle solution. And yet I don’t have a better proposal that’s totally correct.
>
> Why would it be brittle? In c++ there are other contexts where some
> computations (lots of it in microsoft mode) need to be delayed. Other
> than proposing a change of the standard to restrict what can be in
> between the typedef and the type name I also cannot think of another
> reasonable solution. We could force recomputation, but *that* is the
> one I think would be brittle (and possibly non linear complexity).
Right, forcing recomputation is problematic.
I call this brittle because there are a lot of things that end up, directly
or indirectly, querying linkage. If we take the path of delaying just that
computation, analogous to DelayedDiagnostics, then we have to be
able to basically reconstruct all such uses, which is unlikely. The easier
thing is to handle this, as Richard suggests, by relying on delayed parsing;
but that doesn’t actually handle everything, because it’s possible to use
‘this’ in non-delayed contexts.
John.
More information about the cfe-commits
mailing list