public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/7345: parse error when using templated member function from templated base class
@ 2002-07-17 12:46 ronny
0 siblings, 0 replies; 2+ messages in thread
From: ronny @ 2002-07-17 12:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 7345
>Category: c++
>Synopsis: parse error when using templated member function from templated base class
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Wed Jul 17 12:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Ronny Krashinsky
>Release: gcc version 3.0.4
>Organization:
>Environment:
x86, linux
>Description:
compiling this program:
-----------------------------------------------------
//#include<stdio.h>
template<int x>
class A {
public:
template<int y>
int foo() { return (x + y); };
int foo2() { return foo<2>(); };
};
template<int x>
class B : public A<x> {
public:
int bar() {
return ( foo<2>() );
};
};
int main() {
int i;
A<3> a;
i = a.foo<2>();
//printf("%d\n", i);
i = a.foo2();
//printf("%d\n", i);
B<3> b;
i = b.bar();
//printf("%d\n", i);
return(0);
};
-----------------------------------------------------
results in this parse error:
-----------------------------------------------------
bug.cc: In member function `int B<x>::bar()':
bug.cc:16: parse error before `;' token
-----------------------------------------------------
I think that the compiler is not recognizing foo<2> as the name of a function as it should.
I don't know of any workaround to call foo<2> from within B. "A::foo<2>()" doesn't work, "using A::foo<2>" doesn't work, declaring a function pointer doesn't work, etc.
>How-To-Repeat:
compile the program
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.cc"
Ly8jaW5jbHVkZTxzdGRpby5oPgoKdGVtcGxhdGU8aW50IHg+CmNsYXNzIEEgewpwdWJsaWM6CiAg
dGVtcGxhdGU8aW50IHk+CiAgaW50IGZvbygpIHsgcmV0dXJuICh4ICsgeSk7IH07CiAgaW50IGZv
bzIoKSB7IHJldHVybiBmb288Mj4oKTsgfTsKfTsKCgp0ZW1wbGF0ZTxpbnQgeD4KY2xhc3MgQiA6
IHB1YmxpYyBBPHg+IHsKcHVibGljOgogIGludCBiYXIoKSB7IAogICAgcmV0dXJuICggZm9vPDI+
KCkgKTsKICB9Owp9OwoKCmludCBtYWluKCkgewogIGludCBpOwogIEE8Mz4gYTsKICBpID0gYS5m
b288Mj4oKTsKICAvL3ByaW50ZigiJWRcbiIsIGkpOwogIGkgPSBhLmZvbzIoKTsKICAvL3ByaW50
ZigiJWRcbiIsIGkpOwoKICBCPDM+IGI7CiAgaSA9IGIuYmFyKCk7CiAgLy9wcmludGYoIiVkXG4i
LCBpKTsKCiAgcmV0dXJuKDApOwp9OwoKCgoKCg==
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/7345: parse error when using templated member function from templated base class
@ 2002-07-20 9:13 lerdsuwa
0 siblings, 0 replies; 2+ messages in thread
From: lerdsuwa @ 2002-07-20 9:13 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, ronny
Synopsis: parse error when using templated member function from templated base class
State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Sat Jul 20 09:13:38 2002
State-Changed-Why:
Not a bug. Use the following syntax
A<x>::template foo<2>()
Here 'foo<2>' is a function inside a base class that
depends on the template parameter 'x'. So the prefix
'A<x>::' is required. With the prefix, '<' will be treated
as a less-than operator (not the beginning of template
argument) unless the 'template' keyword appears
before 'foo<2>'.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7345
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-07-20 16:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-17 12:46 c++/7345: parse error when using templated member function from templated base class ronny
2002-07-20 9:13 lerdsuwa
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).