Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / g++.dg / abi / covariant5.C
blob03e55583d03583f24989bb27a35bba3963acabc4
1 // Copyright (C) 2005 Free Software Foundation, Inc.
2 // Contributed by Nathan Sidwell 4 Apr 2005 <nathan@codesourcery.com>
4 // { dg-do run }
6 // PR 20746: Covariant return pointer could be null.
8 // Origin: yanliu@ca.ibm.com
9 //         nathan@codesourcery.com
11 struct A {
12   virtual void One ();
14 struct B  { 
15   virtual B *Two ();
16   virtual B &Three ();
19 struct C : A, B
21   virtual C *Two (); 
22   virtual C &Three (); 
24 void A::One () {}
25 B *B::Two()    {return this;}
26 B &B::Three()    {return *this;}
27 C *C::Two ()   {return 0;}
28 C &C::Three ()   {return *(C *)0;}
30 B *Foo (B *b)
32   return b->Two ();
35 B &Bar (B *b)
37   return b->Three ();
40 int main ()
42   C c;
44   /* We should not adjust a null pointer.  */
45   if (Foo (&c))
46     return 1;
47   /* But we should adjust a (bogus) null reference.  */
48   if (!&Bar (&c))
49     return 2;
51   return 0;