This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/7075: Specialization of template in template does not work


>Number:         7075
>Category:       c++
>Synopsis:       Specialization of template in template does not work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 19 04:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Richard Guenther
>Release:        gcc 3.1.1 CVS
>Organization:
>Environment:
Linux bellatrix 2.4.18-rc4-TATUP #2 Tue Mar 19 16:30:05 CET 2002 i686 unknown
>Description:
The attached code fails to compile using any version of g++ which complains

part-broken.cpp:10: template parameters not used in partial specialization:
part-broken.cpp:10:         `T'
part-broken.cpp: In static member function `static void foo<T>::bar<d>::blah(T) 
   [with int d = -46, T = int]':

and then fails to use/recognize the specialization, i.e. exceeds maximum template instantiation depth.
>How-To-Repeat:
g++ -c -Wall part-broken.cpp
>Fix:
One can work around this by adding an extra template parameter to the inner class defaulting to the template class of the outer class. See .cpp file.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="part-broken.cpp"
Content-Disposition: inline; filename="part-broken.cpp"

template <typename T>
struct foo {
	/* works, if template <int d, typename X = T> and use X for T */
	template <int d>
	struct bar {
		static void blah(T x)
		{
			bar<d-1>::blah(x);
		}
	};
	struct bar<0> {
		static void blah(T x)
		{
		}
	};
};

int main(int argc, char **argv)
{
	foo<int>::bar<3>::blah(5);
	return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]