public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: ben@timing.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/7467: method & class w/same name gives unhelpful error.
Date: Thu, 01 Aug 2002 10:46:00 -0000	[thread overview]
Message-ID: <20020801173639.6529.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-08-01 17:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-01 10:46 ben [this message]
2002-10-26  7:47 lerdsuwa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020801173639.6529.qmail@sources.redhat.com \
    --to=ben@timing.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).