1// { dg-do run  }
2// PRMS Id: 6000
3// Bug: g++ gets confused trying to build up a reference to a cast.
4
5class String {
6protected:
7  char *cp;
8public:
9  String(char *incp);
10  String(const String &constStringRef);
11  virtual void virtualFn1(void) const {;}
12};
13
14String::String(char *incp)
15{
16  cp = incp;
17}
18
19String::String(const String &constStringRef)
20{
21// Right here, do an 'info args', and look at the virtual function table
22// pointer: typically junk! Calling the function through that table could
23// do anything, since we're really leaping off into the void. This example
24// goes down with 'SIGBUS', but I've seen 'SIGSEGV' too, and 'SIGILL' is
25// possible.
26
27  cp = constStringRef.cp;
28  constStringRef.virtualFn1();
29}
30
31void foofun(String string)
32{
33  ;
34}
35
36class Class1 {
37public:
38  Class1(const String & constStringRef);
39};
40
41Class1 :: Class1 (const String & constStringRef)
42{
43// If instead of calling the function 'foofun()' here, we just assign
44// 'constStringRef' to a local variable, then the vptr is typically == 0!
45
46  foofun(String(constStringRef));
47}
48
49int main(void)
50{
51  Class1 *class1 = new Class1("Hi!");
52}
53