public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8876: wrong template instantiation
@ 2002-12-09 13:15 bangerth
  0 siblings, 0 replies; 4+ messages in thread
From: bangerth @ 2002-12-09 13:15 UTC (permalink / raw)
  To: benoitsevigny, gcc-bugs, gcc-prs, nobody

Synopsis: wrong template instantiation

State-Changed-From-To: open->feedback
State-Changed-By: bangerth
State-Changed-When: Mon Dec  9 13:15:26 2002
State-Changed-Why:
    Your attachment got lost somehow. Could you possibly send it
    to me so that I can attach it to the report?
    
    Thanks
      Wolfgang

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8876


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/8876: wrong template instantiation
@ 2002-12-09 19:06 bangerth
  0 siblings, 0 replies; 4+ messages in thread
From: bangerth @ 2002-12-09 19:06 UTC (permalink / raw)
  To: benoitsevigny, gcc-bugs, gcc-prs, nobody

Synopsis: wrong template instantiation

State-Changed-From-To: feedback->open
State-Changed-By: bangerth
State-Changed-When: Mon Dec  9 19:06:18 2002
State-Changed-Why:
    Testcase now attached.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8876


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/8876: wrong template instantiation
@ 2002-12-09 18:26 Benoit Sevigny
  0 siblings, 0 replies; 4+ messages in thread
From: Benoit Sevigny @ 2002-12-09 18:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

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>&nbsp;</P>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>
 <DIV></DIV>&gt;From: bangerth@dealii.org 
 <DIV></DIV>
 <DIV></DIV>&gt;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>&gt;To: benoitsevigny@hotmail.com, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org 
 <DIV></DIV>
 <DIV></DIV>&gt;Subject: Re: c++/8876: wrong template instantiation 
 <DIV></DIV>
 <DIV></DIV>&gt;Date: 9 Dec 2002 21:15:28 -0000 
 <DIV></DIV>
 <DIV></DIV>&gt; 
 <DIV></DIV>
 <DIV></DIV>&gt;Synopsis: wrong template instantiation 
 <DIV></DIV>
 <DIV></DIV>&gt; 
 <DIV></DIV>
 <DIV></DIV>&gt;State-Changed-From-To: open-&gt;feedback 
 <DIV></DIV>
 <DIV></DIV>&gt;State-Changed-By: bangerth 
 <DIV></DIV>
 <DIV></DIV>&gt;State-Changed-When: Mon Dec 9 13:15:26 2002 
 <DIV></DIV>
 <DIV></DIV>&gt;State-Changed-Why: 
 <DIV></DIV>
 <DIV></DIV>&gt; Your attachment got lost somehow. Could you possibly send it 
 <DIV></DIV>
 <DIV></DIV>&gt; to me so that I can attach it to the report? 
 <DIV></DIV>
 <DIV></DIV>&gt; 
 <DIV></DIV>
 <DIV></DIV>&gt; Thanks 
 <DIV></DIV>
 <DIV></DIV>&gt; Wolfgang 
 <DIV></DIV>
 <DIV></DIV>&gt; 
 <DIV></DIV>
 <DIV></DIV>&gt;http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&amp;database=gcc&amp;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--


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/8876: wrong template instantiation
@ 2002-12-08 15:06 benoitsevigny
  0 siblings, 0 replies; 4+ messages in thread
From: benoitsevigny @ 2002-12-08 15:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8876
>Category:       c++
>Synopsis:       wrong template instantiation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 08 15:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Benoit Sevigny
>Release:        gcc version 3.2 (mingw special 20020817-1)
>Organization:
>Environment:
Window XP
>Description:
When calling a static function of an explicitely instantiated template structure enclosed in another template structure, the wrong template is being instantiated.
>How-To-Repeat:
compile and run the attached code.

It should print (as with Visual C++ 6.0):

calling function<3> -> in function<3>: l = 1, r = 2
calling function<3> -> in function<3>: l = 2, r = 1
calling function<100> -> in function<100>: l = 1, r = 2
calling function<100> -> in function<100>: l = 2, r = 1

However, if it prints:

calling function<3> -> in function<1>: l = 1, r = 2
calling function<3> -> in function<2>: l = 2, r = 1
calling function<100> -> in function<1>: l = 1, r = 2
calling function<100> -> in function<2>: l = 2, r = 1

Then the wrong function template it being instantiated.
>Fix:
No fix known
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-10  3:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-09 13:15 c++/8876: wrong template instantiation bangerth
  -- strict thread matches above, loose matches on Subject: below --
2002-12-09 19:06 bangerth
2002-12-09 18:26 Benoit Sevigny
2002-12-08 15:06 benoitsevigny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).