[gnu.g++.bug] 3 Bugs

perm@mizar.docs.uu.se (Per Mildner) (05/25/89)

I'm Per-Mildner@AIDA.CSD.UU.SE

 Configuration:
SUN 4 with OS 4
tm.h -> config/tm-sparc+.h
md -> config/sparc.md
g++ version 1.35.0
g++ -Wall -O program.cc

1.
I don't know if this is a bug, but:
It would be useful if structures could have size zero.
This could eg be used ot inherit a bunch of static members.

#include <stream.h>

class foo {
  static int x;
};

int main(int argc, char* argv[]) {
  cout << "sizeof(foo)==" << sizeof(foo) << ".\n"; // says 1 on my system
  return 0;

};

2.
class C {
public:
  int slot;
  friend int bug(C c) {return c.slot;}
};
  
/*
g++ -Wall -c friend-inline-bug.cc
friend-inline-bug.cc:4: warning: `int bug (struct C)' declared but never defined
I get this even if I actually use the function (it gets defined and
works ok).
*/

3.
#include <stream.h>

class base {
 public:
  long field;
  virtual int f () {return 1*field;};
};

class derived : public base {
 public:
  int f () {return 2*field;}
};

struct foo {
  base aa,bb;
};

void bug (base& a, base& b) {
  cout << "a: " << a.f() << ", b: " << b.f() << ".\n";
  struct foo aabb;
  aabb.aa = a;
  aabb.bb = b;
  // This gives a segmentation fault.
  // Similar circumstances did print but used base::f() for both structure components.
  // (which might be the correct behaviour)
  cout << "aabb.aa.f(): " << aabb.aa.f() << ", aabb.bb.f(): " << aabb.bb.f() << ".\n";
};

int main(int argc, char* argv[]) {
  base b;
  derived d;
  b.field=2;
  d.field=11;
  bug(b,d);
  return 0;
};