[PATCH] Instantiate incomplete class used in template method.

Serge Pavlov sepavloff at gmail.com
Tue Apr 7 11:25:27 PDT 2015


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.

Thanks,
--Serge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150408/c89bf86f/attachment.html>


More information about the cfe-commits mailing list