c++/7467: method & class w/same name gives unhelpful error.
ben@timing.com
ben@timing.com
Thu Aug 1 10:46:00 GMT 2002
>Number: 7467
>Category: c++
>Synopsis: method & class w/same name gives unhelpful error.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Aug 01 10:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: ben@timing.com
>Release: gcc version 2.95.3 [FreeBSD] 20010315 (release)
>Organization:
>Environment:
piglet.ttyp3.0$ uname -a
FreeBSD piglet.timing.com 4.3-RELEASE-TSC FreeBSD 4.3-RELEASE-TSC #1: Mon Aug 20 16:03:52 MDT 2001 root@piglet.timing.com:/home/ben/newpig/FreeBSD-tsc-4/sys/compile/SMPIGLET i386
>Description:
When a class is given the same name as a method in your inheritance hierarchy, g++ emits the same error as if the class name were undefined.
Example:
If you have a class, A, with a method A::foo() and then also define a class foo, if you attempt to use a variable of type foo within class A, you get the error "syntax error before `;'" from g++. This is the same error you would get if you mistyped foo as f00.
This error can be easy to reproduce if you have a complex inheritance lattice (perhaps from a third party library) and you accidentally name a class in a program to have the same name as a method in the inheritance lattice. You then end up with the puzzling situation where your newly defined class can be used in some instances, and not in others.
I request a clarification of the syntax error in this case to emit a more particular error message. Since in the scope of the class with the method name that clashes with the class name you are attempting to define a variable of type "method name", the error message should indicate that there is such a clash, or at least that the compiler thinks you're a dummy for trying to declare a variable with a type that has the same name as a method in that classes inheritance hierarchy.
>How-To-Repeat:
Simple test case to reproduce:
#include <iostream>
class A
{
public:
A() {};
void foo() {};
foo bar;
};
class foo
{
public:
foo() {};
};
main()
{
A oink;
// gives same error as:
// B oink;
// (B not defn'd)
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list