1 // { dg-do run  }
2 // PRMS Id: 6000
3 // Bug: g++ gets confused trying to build up a reference to a cast.
4 
5 class String {
6 protected:
7   char *cp;
8 public:
9   String(char *incp);
10   String(const String &constStringRef);
virtualFn1(void)11   virtual void virtualFn1(void) const {;}
12 };
13 
String(char * incp)14 String::String(char *incp)
15 {
16   cp = incp;
17 }
18 
String(const String & constStringRef)19 String::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 
foofun(String string)31 void foofun(String string)
32 {
33   ;
34 }
35 
36 class Class1 {
37 public:
38   Class1(const String & constStringRef);
39 };
40 
Class1(const String & constStringRef)41 Class1 :: 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 
main(void)49 int main(void)
50 {
51   Class1 *class1 = new Class1((char*) "Hi!");
52 }
53