[PATCH] Instantiate incomplete class used in template method.
Richard Smith
richard at metafoo.co.uk
Tue Apr 7 11:43:55 PDT 2015
On 7 Apr 2015 11:28 am, "Serge Pavlov" <sepavloff at gmail.com> wrote:
>
> 2015-04-07 2:23 GMT+06:00 Richard Smith <richard at metafoo.co.uk>:
>>
>> ================
>> Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:4406-4407
>> @@ +4405,4 @@
>> + const TagDecl *DeclToInstantiate = nullptr;
>> + if (TagDecl *Def = TD->getDefinition())
>> + DeclToInstantiate = Def;
>> + else if (!TD->isThisDeclarationADefinition() &&
!TD->isFreeStanding())
>> ----------------
>> What's the purpose of this change? If we have a reference to a
particular `TagDecl`, why don't we always instantiate that declaration?
>>
> If check for invalid declaration is made prior to this one, it seems that
we can always instantiate the type.
> This fix however allows to compile the following code:
>
> template<typename T> void f3() {
> struct AA {
> struct x3 vvv;
> } xx;
> return xx.aaa;
> struct x3 { int aaa; };
> }
>
> It is because at the point where incomplete type is used we instantiate
its definition, which is defined later.Strange, but gcc also compiles this
code. Not sure why this code should be accepted.
That code is ill-formed; we should reject it.
> Thanks,
> --Serge
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150407/daa8f397/attachment.html>
More information about the cfe-commits
mailing list