Bug 35727 - Nested class of specialized template class bug
Summary: Nested class of specialized template class bug
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-28 00:16 UTC by Philippe A. Bouchard
Modified: 2008-12-29 04:06 UTC (History)
2 users (show)

See Also:
Host: Windows XP
Target: MinGW
Build: gcc version 3.4.5 (mingw special)
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe A. Bouchard 2008-03-28 00:16:44 UTC
** I am trying to compile a program that looks like the following but the compiler cannot recognize which class the nested class belongs to:

#include <iostream>


using namespace std;


template <typename T>
	struct A
	{
		class B;
		friend class B;
	};


template <>
	struct A<void>
	{
		class B;
		friend class B;
	};


template <typename T>
	struct A<T>::B
	{
		B() 
        {
            cout << __PRETTY_FUNCTION__ << endl;
        }
	};

    
int main()
{
    A<void>::B b;
}


** Reports:
nesttempspecbug.cpp: In function `int main()':
nesttempspecbug.cpp:35: error: aggregate `A<void>::B b' has incomplete type and cannot be defined
Comment 1 Andrew Pinski 2008-03-28 00:25:21 UTC
This error message is correct as you specialized A<void> but you also need to specialize the nested class as the non specialized version of the nested function will not be used.
Comment 2 Philippe A. Bouchard 2008-03-28 05:20:58 UTC
** Then if I add the following:

template <>
        struct A<void>::B
        {
		B() 
		{
			cout << __PRETTY_FUNCTION__ << endl;
		}
        };


** I get:

nesttempspecbug.cpp:35: error: explicit specialization of non-template `A<void>::B'
nesttempspecbug.cpp:35: error: explicit specialization of non-template `A<void>::B'
Comment 3 Andrew Pinski 2008-12-29 04:06:05 UTC
You just want:
struct A<void>::B
{
	B() 
	{
		cout << __PRETTY_FUNCTION__ << endl;
	}
};

Since you already specialized A<void>, you don't need to specialize  A<void>::B.