OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [abi/] [covariant5.C] - Blame information for rev 718

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// Copyright (C) 2005 Free Software Foundation, Inc.
2
// Contributed by Nathan Sidwell 4 Apr 2005 
3
 
4
// { dg-do run }
5
 
6
// PR 20746: Covariant return pointer could be null.
7
 
8
// Origin: yanliu@ca.ibm.com
9
//         nathan@codesourcery.com
10
 
11
struct A {
12
  virtual void One ();
13
};
14
struct B  {
15
  virtual B *Two ();
16
  virtual B &Three ();
17
};
18
 
19
struct C : A, B
20
{
21
  virtual C *Two ();
22
  virtual C &Three ();
23
};
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;}
29
 
30
B *Foo (B *b)
31
{
32
  return b->Two ();
33
}
34
 
35
B &Bar (B *b)
36
{
37
  return b->Three ();
38
}
39
 
40
int main ()
41
{
42
  C c;
43
 
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;
50
 
51
  return 0;
52
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.