[cfe-dev] A question about template class forwarding definition

Jiangning Liu liujiangning1 at gmail.com
Tue Sep 9 00:00:48 PDT 2014


Hi,

I have a class forwarding definition issue. For the following small test
case, gcc can build pass, but clang(trunk) will build fail.

====================================

template<class T> class B;

template<class T>
class A
{
  public:
    void f(void) const { B<double> e; g(e); }
    void g(B<double> &e) const;
};

template<class T>
class B
{
public:
  T x[9];

  B() {
    for(int i=0;i<9;i++) x[i]=0;
  }
};
$ g++ -std=c++03 -c tt.cc
$ clang++ -std=c++03 -c tt.cc
tt.cc:7:36: error: implicit instantiation of undefined template 'B<double>'
    void f(void) const { B<double> e; g(e); }
                                   ^
tt.cc:1:25: note: template is declared here
template<class T> class B;
                        ^
1 error generated.

====================================

Is this bug in clang?

If not, how should I write the forwarding declaration for class B, and why
gcc can pass?

Thanks,
-Jiangning
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140909/10c035d8/attachment.html>


More information about the cfe-dev mailing list