[cfe-dev] unnecessary implicit instantiation?
Troy Johnson via cfe-dev
cfe-dev at lists.llvm.org
Mon Sep 23 08:06:52 PDT 2019
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190923/e2180a5b/attachment.html>
More information about the cfe-dev
mailing list