Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is this a compiler template bug?

4 views
Skip to first unread message

Thomas Tutone

unread,
Mar 21, 2006, 6:05:35 AM3/21/06
to
In migrating from gcc 3.4.5 to gcc 4.1.0, I'm finding that what I
thought was valid code is failing to compile. I think it's a compiler
bug rather than a coding error, but I'd like confirmation. Here's a
small test case.

gcc 3.4.5 compiles the following cleanly:

struct Foo {
template<class T> int func() const;
};

class Bar {
friend int Foo::func<int>() const; // line 6
};

gcc 4.1.0, however, gives the following compile error for the same
code:

z:\proj\gccerr.cpp:6: error: template-id 'func<int>' for 'int
Foo::func<int>()' does not match any template declaration

But both gcc 3.4.5 and gcc 4.1.0 compile the code cleanly if I change
Foo::func to be non-const:

struct Foo {
template<class T> int func();
};

class Bar {
friend int Foo::func<int>(); // line 6
};

And Comeau compiles both versions of the code without errors.

So is this a bug in gcc 4.10?

Best regards,

Tom


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

oosky...@gmail.com

unread,
Apr 6, 2006, 3:12:21 AM4/6/06
to

Thomas Tutone wrote:
> In migrating from gcc 3.4.5 to gcc 4.1.0, I'm finding that what I
> thought was valid code is failing to compile. I think it's a compiler
> bug rather than a coding error, but I'd like confirmation. Here's a
> small test case.
>
> gcc 3.4.5 compiles the following cleanly:
>
> struct Foo {
> template<class T> int func() const;
> };
>
> class Bar {
> friend int Foo::func<int>() const; // line 6
> };
>
> gcc 4.1.0, however, gives the following compile error for the same
> code:
>
> z:\proj\gccerr.cpp:6: error: template-id 'func<int>' for 'int
> Foo::func<int>()' does not match any template declaration
>
> But both gcc 3.4.5 and gcc 4.1.0 compile the code cleanly if I change
> Foo::func to be non-const:
>
> struct Foo {
> template<class T> int func();
> };
>
> class Bar {
> friend int Foo::func<int>(); // line 6
> };
>
--------------------------------------------------------------
change follow code,waht error will come out?
struct Foo {
template<class T>func() const;
};

class Bar {
friend template<class T> Foo::func<int>() const; // line 6
};

Thomas Tutone

unread,
Apr 7, 2006, 3:37:19 AM4/7/06
to
oosky...@gmail.com wrote:

Your code is mal-formed:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 2: error: omission of explicit type is nonstandard
("int"
assumed)


template<class T>func() const;

^

"ComeauTest.c", line 6: error: "template" is not allowed
Comeau C++ 4.2.43 and above supports template-template-parameters
OR You are using template in the wrong place


friend template<class T> Foo::func<int>() const; // line 6

In any case, I reported my test case to the gcc folks, who have
confirmed it as a compiler bug:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26912

Best regards,

Tom

0 new messages