Subject: bin/2786: bug in g++: local names clash with member names.
To: None <gnats-bugs@gnats.netbsd.org>
From: Taras Ivanenko <ivanenko@ctps01.mit.edu>
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
>Last-Modified:
>Originator:     Taras Ivanenko
>Organization:
MIT
	
>Release:        <NetBSD-current source date> Jul 1?, 1996
>Environment:
	
System: NetBSD ctps01.mit.edu 1.2_BETA NetBSD 1.2_BETA (ctp-sun-slc) #1: Wed Jul 17 11:34:21 EDT 1996 ivanenko@ctps01.mit.edu:/usr/src/sys/arch/sparc/compile/ctp-sun-slc sparc


>Description:
	

Here is the code:

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

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

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

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

  d.f(var);
}

/* End of file */

When I compile it with gcc 2.7.2 I am getting an error
g++ -v /ctpa03/ivanenko/tmp/bug.cc
 /usr/bin/cc -v /ctpa03/ivanenko/tmp/bug.cc -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/bug.cc /var/tmp/cc021710.ii
GNU CPP version 2.7.2 (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/include
End of search list.
 /usr/libexec/cc1plus /var/tmp/cc021710.ii -quiet -dumpbase bug.cc -version -o /var/tmp/cc021710.s
GNU C++ version 2.7.2 (sparc) compiled by GNU C version 2.7.2.
/ctpa03/ivanenko/tmp/bug.cc: In function `int main()':
/ctpa03/ivanenko/tmp/bug.cc:26: request for member `var' is ambiguous

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

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.
>How-To-Repeat:
	
see above
>Fix:
	
>Audit-Trail:
>Unformatted: