<div dir="ltr">DE is not complete while you instantiate the class body of Parent. Using sizeof gives a better diagnostic:<div><br><div><div>template <typename DE></div><div>struct Parent</div><div>{</div><div>    static const int value = sizeof(DE);</div></div><div>...</div><div><div>t.cpp:6:30: error: invalid application of 'sizeof' to an incomplete type 'Child<int, 4>'</div><div>    static const int value = sizeof(DE);</div><div>                             ^~~~~~~~~~</div><div>t.cpp:14:16: note: in instantiation of template class 'Parent<Child<int, 4> >' requested here</div><div>struct Child : Parent< Child<T,N> ></div><div>               ^</div><div>t.cpp:22:18: note: in instantiation of template class 'Child<int, 4>' requested here</div><div>    Child<int,4> c;</div><div>                 ^</div><div>t.cpp:14:8: note: definition of 'Child<int, 4>' is not complete until the closing '}'</div><div>struct Child : Parent< Child<T,N> ></div><div>       ^</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 2, 2016 at 2:08 PM, Diptorup Deb via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
In the below code I am trying to use CRTP to use the static member "value" from the Child class in the Parent class. When compiling the code with g++ 5.2.1 with the "-pedantic" flag, I am able to compile without errors or warning, and on execution both c.print_value(); and Child<int,4>::print_value(); print out 4.<br>
<br>
------------------------------------------<br>
#include <iostream><br>
<br>
template <typename DE><br>
struct Parent<br>
{<br>
    static const int value = DE::value;<br>
    static void print_value ()<br>
    {<br>
        std::cout << "Value : " << value << '\n';<br>
    }<br>
};<br>
<br>
template <typename T, int N><br>
struct Child : Parent< Child<T,N> ><br>
{<br>
    static const int value = N;<br>
};<br>
<br>
int<br>
main ()<br>
{<br>
    Child<int,4> c;<br>
    c.print_value();<br>
    Child<int,4>::print_value();<br>
}<br>
------------------------------------------<br>
<br>
However when compiling the same code with clang++3.7, I encounter compilation failures.<br>
<br>
crtp_clang_error.cpp:9:32: error: no member named 'value' in 'Child<int, 4>'<br>
static const int value = DE::value;<br>
                       ~~~~^<br>
crtp_clang_error.cpp:27:16: note: in instantiation of template class 'Parent<Child<int, 4> >' requested here<br>
struct Child : Parent< Child<T,N> ><br>
           ^<br>
crtp_clang_error.cpp:38:16: note: in instantiation of template class 'Child<int, 4>' requested here<br>
  Child<int,4> c;<br>
           ^<br>
crtp_clang_error.cpp:40:3: error: no member named 'print_value' in 'Child<int, 4>'; did you mean 'Parent<Child<int, 4> >::print_value'?<br>
  Child<int,4>::print_value();<br>
  ^~~~~~~~~~~~~~~~~~~~~~~~~<br>
  Parent<Child<int, 4> >::print_value<br>
crtp_clang_error.cpp:11:15: note: 'Parent<Child<int, 4> >::print_value' declared here<br>
  static void print_value ()<br>
<br>
Would kindly request some insight into this behaviour.<br>
<br>
Best,<br>
Dipto<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>