Bug 17981 - parse error on template method of template class
Summary: parse error on template method of template class
Status: RESOLVED DUPLICATE of bug 795
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2004-10-13 20:08 UTC by David Fang
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: *
Target: *
Build: *
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Fang 2004-10-13 20:08:48 UTC
----------------------------
gcc/g++ versions (2):

1)
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-
prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --enable-
languages=c,c++,f77,objc,java,ada --disable-checking --libdir=/usr/lib --enable-
libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-
system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux
Thread model: posix
gcc version 3.3.3 (SuSE Linux)

2)
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1640)
(no more information available from g++ -v on this platform)

-----------------------------------------------
command line:

g++ --save-temps main.cc -o main

------------------------------------------------
compiler output (both versions):

In file included from main.cc:5:
parse-bug.tcc: In member function `ptr<S> foo::func1() const':
parse-bug.tcc:30: error: syntax error before `>' token

------------------------------------------------
remarks:

Apologies if this bug has already been reported, 
but I couldn't find it in Bugzilla after 20 minutes of
queries.  I've initially flagged this with normal severity, 
but it may actually be worse because I cannot find a workaround.  

g++-3.4.0 accepts the input below and behaves correctly
in the context of more complicated code.
The input given below is a reduced version that 
exhibits the problem.  

I've tried a few workarounds such as removing the 
explicit template argument, but neither g++3.3.3 nor
3.4.0 accept it, b/c no matching function is found. 

I hope a solution is under way.

regards, 
David

------------------------------------------------
the preprocessed input file follows:
------------- begin "main.ii" ------------------
# 1 "main.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "main.cc"




# 1 "parse-bug.tcc" 1







# 1 "parse-bug.h" 1
# 12 "parse-bug.h"
template <class T>
class ptr {
private:
        T* p;
public:
        ptr(T* t) : p(t) { }
        ~ptr() { }

        template <class S>
        ptr<S>
        is_a_xfer(void) const;

};

class foo {
protected:
        ptr<foo> k;
public:
        foo() : k(0) { }

        template <class T>
        ptr<T> func1(void) const;







};
# 9 "parse-bug.tcc" 2



template <class T>
template <class S>
ptr<S>
ptr<T>::is_a_xfer(void) const {
        return ptr<S>(dynamic_cast<S*>(p));
}

template <class T>
ptr<T>
foo::func1(void) const {
# 30 "parse-bug.tcc"
        return k.is_a_xfer<T>();







}
# 6 "main.cc" 2

int
main (int argc, char* argv[]) {
        const foo bar;
        ptr<foo> ip = bar.func1<foo>();

        return 0;
}
Comment 1 Andrew Pinski 2004-10-13 20:17:15 UTC
3.4.0 accepts the code for me and runs.
Comment 2 Andrew Pinski 2004-10-13 20:18:49 UTC
Yes this was reported before PR 795.

*** This bug has been marked as a duplicate of 795 ***
Comment 3 Wolfgang Bangerth 2004-10-13 21:10:17 UTC
The workaround is to write 
        return k.template is_a_xfer<T>(); 
 
W. 
Comment 4 David Fang 2004-10-13 21:14:19 UTC
Subject: Re:  parse error on template method of template class

Thank you for the feedback.  How come when I searched for the keywords
"parse error template method" on bugzilla, I get the infamous
`Zarro Boogs found.'?

I was certain this bug would've been reported ages ago, and it was, #2 on
the most frequent bugs list, which I only later checked.

Perhaps bugzilla's query engine needs some tuning?

David

> ------- Additional Comments From bangerth at dealii dot org  2004-10-13 21:10 -------
> The workaround is to write
>         return k.template is_a_xfer<T>();

Comment 5 Andrew Pinski 2004-10-13 21:44:52 UTC
Most likely you searched only the open bugs.