| View previous topic :: View next topic |
| Author |
Message |
Kevin Wan Guest
|
Posted: Fri Feb 27, 2004 2:57 am Post subject: Please help to judge if it's a bug of g++! |
|
|
I have such a program!
template <typename T>
struct A
{
template <bool b>
void aaa() {}
};
template <typename T>
struct B
{
A<int> a;
void bbb() { a.aaa<true>(); }
};
int main()
{
B<int> b;
b.bbb();
}
$ g++ test.cc
template.cc: In member function `void B<T>::bbb()':
template.cc:12: syntax error before `;' token
$ g++ --version
g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
Please help to confirm if it's a bug of g++!
Thanks a lot!
jfwan
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Fri Feb 27, 2004 3:16 am Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
* [email]jfwan (AT) vip (DOT) sina.com[/email] (Kevin Wan) schriebt:
| Quote: |
template <typename T
struct A
{
template
void aaa() {}
};
template
struct B
{
A
void bbb() { a.aaa<true>(); }
};
int main()
{
B<int> b;
b.bbb();
}
$ g++ test.cc
template.cc: In member function `void B<T>::bbb()':
template.cc:12: syntax error before `;' token
$ g++ --version
g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
|
$ g++ --version | grep GCC
g++ (GCC) 3.3
$ g++ -pedantic -ansi main.cpp
main.cpp:11: error: parse error before `;' token
main.cpp: In member function `void B<T>::bbb()':
main.cpp:12: error: parse error before `;' token
$ _
However, Microsoft Visual C++ 7.1 and Comeau Online,
<url: http://www.comeaucomputing.com/tryitout/>,
compile the same code OK, no errors.
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Feb 27, 2004 3:18 am Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
"Kevin Wan" <jfwan (AT) vip (DOT) sina.com> wrote
| Quote: | I have such a program!
template <typename T
struct A
{
template
void aaa() {}
};
template
struct B
{
A
void bbb() { a.aaa<true>(); }
};
int main()
{
B<int> b;
b.bbb();
}
|
It's a bug. Here's a hackish workaround -- only useful if aaa isn't
part of the public interface.
Jonathan
-----------------
template<bool b> struct dummy { };
template <typename T>
struct A
{
template <bool b>
void aaa(dummy<b>) {}
};
template <typename T>
struct B
{
A<int> a;
void bbb() { a.aaa(dummy<true>()); }
};
int main()
{
B<int> b;
b.bbb();
}
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Fri Feb 27, 2004 5:39 pm Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
"Kevin Wan" <jfwan (AT) vip (DOT) sina.com> wrote
| Quote: | I have such a program!
template <typename T
struct A
void bbb() { a.aaa
|
true is not a type name.
a.aaa<bool>();
or change A::aaa to take a bool template arg. It's not clear from the code snippet you
provided what you intend to do.
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Feb 27, 2004 5:46 pm Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
"Ron Natalie" <ron (AT) sensor (DOT) com> wrote
| Quote: |
"Kevin Wan" <jfwan (AT) vip (DOT) sina.com> wrote
I have such a program!
template <typename T
struct A
void bbb() { a.aaa
true is not a type name.
a.aaa<bool>();
or change A::aaa to take a bool template arg. It's not clear from
the code snippet you
provided what you intend to do.
|
I think the OP's example is correct. true is a template argument for
the member template aaa of A, which has a bool parameter, not a
typename parameter.
Jonathan
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Fri Feb 27, 2004 5:59 pm Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
Kevin Wan wrote in news:5cea9465.0402261857.7930148f (AT) posting (DOT) google.com:
| Quote: | I have such a program!
template <typename T
struct A
{
template
void aaa() {}
};
template
struct B
{
A
void bbb() { a.aaa<true>(); }
|
This should compile, but there is a bug in gcc, replace with:
void bbb() { a.template aaa<true>(); }
| Quote: | };
int main()
{
B<int> b;
b.bbb();
}
[snip]
Please help to confirm if it's a bug of g++!
|
Yep, but it isn't in the upcoming 3.4 release.
PS. I tried the above code on 4 compilers and non of them complained
about the unnesassery .template
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Fri Feb 27, 2004 6:07 pm Post subject: Re: Please help to judge if it's a bug of g++! |
|
|
"Jonathan Turkanis" <technews (AT) kangaroologic (DOT) com> wrote
| Quote: |
I think the OP's example is correct. true is a template argument for
the member template aaa of A, which has a bool parameter, not a
typename parameter.
|
Oops, so it does. Sorry about that.
|
|
| Back to top |
|
 |
|