[gnu.g++.bug] 1.35.0 bugs

thewalt@RITZ.CIVE.CMU.EDU (Chris Thewalt) (09/14/89)

I attempted to post this last week and it never appeared, so here it is
again.  I have 2 apparent bugs, one involving const definition and the
other allowing access of a private member without error.

BUG 1:
#############################################################################
Const declarations are allowed in header files, but when I include
the header file shown below, actual definition takes place for variable "a"
in each .cc file, resulting in "_a is multiply defined" errors at link time.

Details: 
	Microvax II running Ultrix 2.2
	g++ version 1.35.0


foo.h:
------
const int a = 1;

foo1.cc:
--------
#include "foo.h"

int x = a;

foo2.cc:
--------
#include "foo.h"

int y = a;



BUG 2
#############################################################################
In the function shown below, a private member of Class2 (c2.flag) is 
accessed without error even though the function is not a friend of Class2.

Details:  
	Microvax II running Ultrix 2.2
	g++ version 1.35.0

Compile log(lines folded by me):

g++ version 1.35.0
 /usr/misc/.gnu/lib/compilers/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ \
 -D__cplusplus -Dvax -Dunix -D__vax__ -D__unix__ foo.cc /tmp/cc001531.cpp
GNU CPP version 1.35
 /usr/misc/.gnu/lib/compilers/gcc-cc1plus /tmp/cc001531.cpp -quiet -dumpbase \
 foo.cc -noreg -version -o /tmp/cc001531.s
GNU C++ version 1.35.0 (vax) compiled by GNU C version 1.35.
 as /tmp/cc001531.s -o foo.o

----------------------------------------------------------------------------
foo.cc:
-------
#include "foo.h"


Class1& operator*(Class1& c1, Class2& c2)
{
    if(c1.flag != c2.flag)         // c2.flag should not be accessible
	;
}

----------------------------------------------------------------------------
foo.h:
------
// #include <stream.h>

class Class2 {
    int flag;
  public:
    Class2();
    ~Class2();
    friend Class2& operator*(double,   Class2&);
    friend Class2& operator*(Class2&, double  );
};

class Class1 {
    int flag;
  public:
    Class1();
    ~Class1();
    friend Class1& operator*(Class1&, Class2&);
};


---- Chris thewalt@ce.cmu.edu
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Christopher Robin Thewalt		These opinions are not necessarily
thewalt@ce.cmu.edu			shared by my employer...
Carnegie Mellon University