<div dir="ltr">You can't use a forward declaration in contexts where object's size must be known. Note that your member function g is fine as B only appears in the parameter list. It can also appear as return type. Declaring pointers is also fine but the moment you try to construct an actual object the type will have to be fully defined. I think this is a gcc bug.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 9, 2014 at 5:00 PM, Jiangning Liu <span dir="ltr"><<a href="mailto:liujiangning1@gmail.com" target="_blank">liujiangning1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I have a class forwarding definition issue. For the following small test case, gcc can build pass, but clang(trunk) will build fail.</div><div><br></div><div>====================================</div><div><br></div><div>template<class T> class B;</div><div><br></div><div>template<class T></div><div>class A</div><div>{</div><div> public:</div><div> void f(void) const { B<double> e; g(e); }</div><div> void g(B<double> &e) const;</div><div>};</div><div><br></div><div>template<class T></div><div>class B</div><div>{</div><div>public:</div><div> T x[9];</div><div><br></div><div> B() {</div><div> for(int i=0;i<9;i++) x[i]=0;</div><div> }</div><div>};</div><div>$ g++ -std=c++03 -c tt.cc</div><div>$ clang++ -std=c++03 -c tt.cc</div><div>tt.cc:7:36: error: implicit instantiation of undefined template 'B<double>'</div><div> void f(void) const { B<double> e; g(e); }</div><div> ^</div><div>tt.cc:1:25: note: template is declared here</div><div>template<class T> class B;</div><div> ^</div><div>1 error generated.</div><div><br></div><div><div>====================================</div></div><div><br></div><div>Is this bug in clang?</div><div><br></div><div>If not, how should I write the forwarding declaration for class B, and why gcc can pass?</div><div><br></div><div>Thanks,</div><div>-Jiangning</div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>