[cfe-dev] unnecessary implicit instantiation?

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 23 09:23:19 PDT 2019


I believe the rules are that since 'M' is not dependent on any template
parameters, it can be checked without deferring until the point of
instantiation. (& that it isn't /required/ to be checked - it's up to the
compiler, so both GCC and Clang are correct here)

On Mon, Sep 23, 2019 at 8:07 AM Troy Johnson via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> If there's a different email list for C++ language questions like this,
> please let me know, since I'm trying establish which compiler's behavior is
> correct before I try to change anything in Clang.  The standard is a little
> fuzzy on this matter because it says that the instantiation occurs as
> needed, and one could argue that one does not need to know the size of a
> static data member in order to use the class type as part of another
> definition.  Clang seems to want the whole definition of the class,
> including static data, to be fully defined before using it.
>
> -Troy
> ------------------------------
> *From:* cfe-dev <cfe-dev-bounces at lists.llvm.org> on behalf of Troy
> Johnson via cfe-dev <cfe-dev at lists.llvm.org>
> *Sent:* Wednesday, September 18, 2019 4:26 PM
> *To:* cfe-dev at lists.llvm.org <cfe-dev at lists.llvm.org>
> *Subject:* [cfe-dev] unnecessary implicit instantiation?
>
> Clang issues an error for the following code, whereas the GNU compiler
> does not.  Based on the standard, I think that an implicit instantiation
> should not occur because the compiler is not yet allocating an object, and
> that would mean that Clang is incorrectly issuing an error and GNU is
> correct to not issue any error.
>
> Is my understanding correct?
>
> > cat t.cpp
> template <typename T> class A;
>
> template <typename T>
> struct B {
>   static A<int> M;
> };
>
> template <typename T> A<int> B<T>::M;
> > g++ -c t.cpp
> > clang -c t.cpp
> t.cpp:8:36: error: implicit instantiation of undefined template 'A<int>'
> template <typename T> A<int> B<T>::M;
>                                    ^
> t.cpp:1:29: note: template is declared here
> template <typename T> class A;
>                             ^
> 1 warning and 1 error generated.
>
>
> Thanks,
> Troy
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190923/a547277a/attachment.html>


More information about the cfe-dev mailing list