Subject: bin/2786: bug in g++: local names clash with member names.
To: None <>
From: Taras Ivanenko <>
List: netbsd-bugs
Date: 09/28/1996 20:40:23
>Number:         2786
>Category:       bin
>Synopsis:       the compiler does not separate local variable names and class members with the same names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 28 17:50:01 1996
>Originator:     Taras Ivanenko
>Release:        <NetBSD-current source date> Jul 1?, 1996
System: NetBSD 1.2_BETA NetBSD 1.2_BETA (ctp-sun-slc) #1: Wed Jul 17 11:34:21 EDT 1996 sparc


Here is the code:

class def1 {
  int var;
  def1() { var = 1; };
  ~def1() {};

class def2 {
  int var;
  def2() { var = 2; };
  ~def2() {};

class def3 : public def1, public def2 {
  int f(int) {return def1::var + def2::var;};

main() {
  def3 d;
  int var = 3;


/* End of file */

When I compile it with gcc 2.7.2 I am getting an error
g++ -v /ctpa03/ivanenko/tmp/
 /usr/bin/cc -v /ctpa03/ivanenko/tmp/ -lg++ -lstdc++ -lm
gcc version 2.7.2
 /usr/libexec/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=7 -Dunix -Dsparc -D__NetBSD__ -D__KPRINTF_ATTRIBUTE__ -D__unix__ -D__sparc__ -D__NetBSD__ -D__KPRINTF_ATTRIBUTE__ -D__unix -D__sparc -Asystem(unix) -Asystem(NetBSD) -Acpu(sparc) -Amachine(sparc) /ctpa03/ivanenko/tmp/ /var/tmp/cc021710.ii
GNU CPP version 2.7.2 (sparc)
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/libexec/cc1plus /var/tmp/cc021710.ii -quiet -dumpbase -version -o /var/tmp/cc021710.s
GNU C++ version 2.7.2 (sparc) compiled by GNU C version 2.7.2.
/ctpa03/ivanenko/tmp/ In function `int main()':
/ctpa03/ivanenko/tmp/ request for member `var' is ambiguous

The variable 'var' in main() has nothing to do with def1::var or

I saw this error on several systems, I believe it is not
system-specific. The output above was produced on NetBSD-1.2/sparc, 
I tested also on NetBSD-1.2/mac68k, Sparc/Solaris.

As a hint I can say that g++ 2.6.3 compile the code without a warning 
(but I did not check correctness)

I sent the report to bugs-g++ too.
see above