c++/7345: parse error when using templated member function from templated base class
ronny@mit.edu
ronny@mit.edu
Wed Jul 17 12:46:00 GMT 2002
>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==
More information about the Gcc-prs
mailing list