This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Conflict between template class name and struct field name
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Conflict between template class name and struct field name
- From: Andy Johnson <andyj at mc dot com>
- Date: Fri, 19 Jan 2001 16:57:58 -0500
- Organization: Mercury Computer Systems
If I declare a template class (e.g. template <class T> stack ...) and
then later declare a struct with a field named "stack", I get a syntax
error. Here is an example of a program that fails:
---
template <class X>
class stack {
X * val;
stack * next;
stack() {}
};
typedef struct {
void * val;
struct {
int x;
void * y;
} stack; // <<<--- syntax error on this line
struct {
int a;
void * b;
} heap;
}foo ;
int main() {
foo bar;
}
---
I realize that the problem can easily be solved by changing the
field name "stack" to "mystack", but this is already a documented
interface in a C-based API specification. This only showed up
when a C++ user, who included both <stack> and the C-based
API header got the syntax error.
It would appear that the lexer is transforming the "stack" field specifier
into a typespec, rather than an identifier, even though it should not be
doing so in this particular context.
Is this a known problem, and is there an available patch? We are
currently using gcc-2.95.2, but this problem exists all the way back
in gcc-2.7.2.
-AndyJ
--
E. Andrew Johnson Tel: 978-256-0052 x1482
Mercury Computer Systems Fax: 978-244-0520
199 Riverneck Road andyj@mc.com
Chelmsford, MA 01824-2820 http://www.ma.ultranet.com/~andyjnsn