This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9380: nested template problem for methods without argument : parsing error
- From: picaud dot vincent at wanadoo dot fr
- To: gcc-gnats at gcc dot gnu dot org
- Date: 20 Jan 2003 23:19:31 -0000
- Subject: c++/9380: nested template problem for methods without argument : parsing error
- Reply-to: picaud dot vincent at wanadoo dot fr
>Number: 9380
>Category: c++
>Synopsis: nested template problem for methods without argument : parsing error
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon Jan 20 23:26:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: picaud.vincent@wanadoo.fr
>Release: gcc 3.2.1
>Organization:
>Environment:
RedHat 7.1, i686 (I have installed the release gcc 3.2.1 without any problem, the original one (RH7.1) was gcc 2.96)
>Description:
Dear GCC Team,
First of all I hope i won't do you waste your time... I use gcc every time in my work and it's a marvelous compiler !
But I think I have found a bug, please consider the short code given in How to Repeat :
When I define a method with no argument, like the method "how_many()" I can't use it in a templated function (or class) like with the function foo_2<>(...)... I get a parsing error (before "(") from the compiler.
The problem doesn't happen with the function foo_1 (which is not templated).
I hope that you will be able to reproduce the problem : for that simply (try to) compile my short example.
Regards,
>How-To-Repeat:
enum topological_dimension {
Vertex=0,
Edge=1,
Face=2,
Volume=3,
};
template<topological_dimension dim_1>
class A
{
public:
template<topological_dimension dim_2>
void how_many() const
{
}
};
// This works
// Edge for example: Vertex, Face... give the same result
void foo_1(const A<Edge>& a)
{
a.how_many<Vertex>();
// Vertex for example:Edge, Face... give the same result
}
// This doesn't work : compiler error :-( (gcc 3.2.1)
//
template<topological_dimension dim>
void foo_2(const A<dim>& a)
{
a.how_many<Vertex>(); // <-- Error parsing this line
// Vertex for example: Edge, Face...give the same result
}
main()
{
}
>Fix:
To avoid the compilation problem, I use the simple following trick :
I introduce an articifial class id_foo<> doing nothing appart being an argument of the function how_many...
enum topological_dimension {
Vertex=0,
Edge=1,
Face=2,
Volume=3,
};
template<topological_dimension dim_1>
struct id_foo
{
};
template<topological_dimension dim_1>
class A
{
public:
template<topological_dimension dim_2>
void how_many(const id_foo<dim_2>& id) const
{
}
};
// Now, this works... but it's not really convenient...
//
template<topological_dimension dim>
void foo_2(const A<dim>& a)
{
a.how_many<Vertex>(id_foo<Vertex>()); // ok...
a.how_many(id_foo<Vertex>()); // also ok...
}
main()
{
}
>Release-Note:
>Audit-Trail:
>Unformatted: