summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.jason/rvalue1.C
blob: 277d594b818fa40ccd8d389316ba99da76484bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// { dg-do run  }
// PRMS Id: 6000
// Bug: g++ gets confused trying to build up a reference to a cast.

class String {
protected:
  char *cp;
public:
  String(char *incp);
  String(const String &constStringRef);
  virtual void virtualFn1(void) const {;}
};

String::String(char *incp)
{
  cp = incp;
}

String::String(const String &constStringRef)
{
// Right here, do an 'info args', and look at the virtual function table
// pointer: typically junk! Calling the function through that table could
// do anything, since we're really leaping off into the void. This example
// goes down with 'SIGBUS', but I've seen 'SIGSEGV' too, and 'SIGILL' is
// possible.

  cp = constStringRef.cp;
  constStringRef.virtualFn1();
}

void foofun(String string)
{
  ;
}

class Class1 {
public:
  Class1(const String & constStringRef);
};

Class1 :: Class1 (const String & constStringRef)
{
// If instead of calling the function 'foofun()' here, we just assign
// 'constStringRef' to a local variable, then the vptr is typically == 0!

  foofun(String(constStringRef));
}

int main(void)
{
  Class1 *class1 = new Class1((char*) "Hi!");
}