[cfe-dev] template specialization and redecls

Craig Silverstein csilvers at google.com
Mon Nov 22 17:33:16 PST 2010


I'm seeing behavior that mystifies me.  Can someone explain it?

Consider this code:
---
struct B {
  template<class T> class C;
  template<class T> friend class C;
  //friend class C<float>;
};

template<class T> class C {
};

C<int>* foo;
---

When I look at the CXXRecordDecl for C<int> (on the last line), and
look at all the redecls (from redecls_begin() to redecls_end()), I see
only one redecl, for the definition of class C on line 7.

But if I uncomment line 4, suddenly I see 3 redecls: one for line 2,
one for line 3, and one for line 7.

Why would adding friendship on a specialization version of C cause the
other items in B to become a redecl of C?

Also, what is the 'proper' contents of the redecls of C?  Should it
only include declarations that are visible at the 'C<int>* foo' line?
That is, the behavior when line 4 is commented out is correct, and the
behavior when I uncomment line 4 is incorrect?

craig



More information about the cfe-dev mailing list