[cfe-dev] template specialization and redecls
Douglas Gregor
dgregor at apple.com
Mon Nov 29 08:02:27 PST 2010
On Nov 22, 2010, at 5:33 PM, Craig Silverstein wrote:
> 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?
That sounds very broken; are B::C and ::C somehow getting tangled together?
> 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?
Line 4 shouldn't have any effect on ::C<int>.
- Doug
More information about the cfe-dev
mailing list