c++/8876: wrong template instantiation

Benoit Sevigny benoitsevigny@hotmail.com
Mon Dec 9 18:26:00 GMT 2002


The following reply was made to PR c++/8876; it has been noted by GNATS.

From: "Benoit Sevigny" <benoitsevigny@hotmail.com>
To: bangerth@dealii.org, benoitsevigny@hotmail.com, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/8876: wrong template instantiation
Date: Mon, 09 Dec 2002 21:18:22 -0500

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_252a_61df_4e24
 Content-Type: text/html
 
 <html><div style='background-color:'><DIV>
 <P>Thanks for the quick reply.</P>
 <P>Here's the offending code.<BR></P></DIV>
 <P>Regards</P>
 <DIV></DIV>
 <P>Benoit Sevigny</P>
 <P><BR> </P>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>>From: bangerth@dealii.org 
 <DIV></DIV>
 <DIV></DIV>>Reply-To: bangerth@dealii.org, benoitsevigny@hotmail.com, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org 
 <DIV></DIV>
 <DIV></DIV>>To: benoitsevigny@hotmail.com, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org 
 <DIV></DIV>
 <DIV></DIV>>Subject: Re: c++/8876: wrong template instantiation 
 <DIV></DIV>
 <DIV></DIV>>Date: 9 Dec 2002 21:15:28 -0000 
 <DIV></DIV>
 <DIV></DIV>> 
 <DIV></DIV>
 <DIV></DIV>>Synopsis: wrong template instantiation 
 <DIV></DIV>
 <DIV></DIV>> 
 <DIV></DIV>
 <DIV></DIV>>State-Changed-From-To: open->feedback 
 <DIV></DIV>
 <DIV></DIV>>State-Changed-By: bangerth 
 <DIV></DIV>
 <DIV></DIV>>State-Changed-When: Mon Dec 9 13:15:26 2002 
 <DIV></DIV>
 <DIV></DIV>>State-Changed-Why: 
 <DIV></DIV>
 <DIV></DIV>> Your attachment got lost somehow. Could you possibly send it 
 <DIV></DIV>
 <DIV></DIV>> to me so that I can attach it to the report? 
 <DIV></DIV>
 <DIV></DIV>> 
 <DIV></DIV>
 <DIV></DIV>> Thanks 
 <DIV></DIV>
 <DIV></DIV>> Wolfgang 
 <DIV></DIV>
 <DIV></DIV>> 
 <DIV></DIV>
 <DIV></DIV>>http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8876 
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV></div><br clear=all><hr>Protect your PC - <a href="http://g.msn.com/8HMHEN/2024">Click here</a> for McAfee.com VirusScan Online </html>
 ------=_NextPart_000_252a_61df_4e24
 Content-Type: text/plain; name="gccbug.cxx"; format=flowed
 Content-Transfer-Encoding: 8bit
 Content-Disposition: attachment; filename="gccbug.cxx"
 
 #include <stdio.h>
 
 template<int l, int r> struct selector {
 	enum { SUM	= l + r, CONSTANT =	100 };
 };
 
 template<int f> struct function {
 	template<typename L, typename R> struct special {
 		static void func()
 		{
 			printf("in function<%d>: l = %d, r = %d\n", f, L::PARAM, R::PARAM);
 		}
 	};
 };
 template<> struct function<3> {
 	template<typename L, typename R> struct special {
 		static void func()
 		{
 			printf("in function<3>: l = %d, r = %d\n", f, L::PARAM, R::PARAM);
 		}
 	};
 };
 template<> struct function<100> {
 	template<typename L, typename R> struct special {
 		static void func()
 		{
 			printf("in function<100>: l = %d, r = %d\n", f, L::PARAM, R::PARAM);
 		}
 	};
 };
 
 template<int l> struct object {
 
 	enum { PARAM = l };
 
 	template<int r> inline void sum(const object<r> &arg)
 	{
 		printf("calling function<%d> -> ", selector< l, r>::SUM);
 
 		function< selector< l, r>::SUM >::special< object<l>, object<r> >::func();
 	}
 	template<int r> inline void constant(const object<r> &arg)
 	{
 		printf("calling function<%d> -> ", selector< l, r>::CONSTANT);
 
 		function< selector< l, r>::CONSTANT >::special< object<l>, object<r> 
  >::func();
 	}
 };
 
 int main(int argc, const char *argv[])
 {
 	object<1> obj1; object<2> obj2;
 
 	obj1.sum(obj2);			// this should print: "in function<3>: l = 1, r = 2"
 	obj2.sum(obj1);			// this should print: "in function<3>: l = 2, r = 1"
 
 	obj1.constant(obj2);	// this should print: "in function<100>: l = 1, r = 2"
 	obj2.constant(obj1);	// this should print: "in function<100>: l = 2, r = 1"
 
 	return 0;
 }
 
 
 ------=_NextPart_000_252a_61df_4e24--



More information about the Gcc-prs mailing list