summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/is_base_of.C
blob: 8afa532e1cddb4befc4854e639081515cce5358d (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// { dg-do run }
#include <cassert>

class A1
{ 
  double a;
  double b;  
};

class A2
{ 
  double a;
  double b;
};

class B
: private A1 { };

class C
: private A1, private A2 { };

union U
{ 
  double a;
  double b;
};

template<typename T, typename U>
  bool
  f()
  { return __is_base_of(T, U); } 

template<typename T, typename U>
  class My
  {
  public:
    bool
    f()
    { return !!__is_base_of(T, U); }
  };

template<typename T, typename U>
  class My2
  {
  public:
    static const bool trait = __is_base_of(T, U);
  };

template<typename T, typename U>
  const bool My2<T, U>::trait;

template<typename T, typename U, bool b = __is_base_of(T, U)>
  struct My3_help
  { static const bool trait = b; };

template<typename T, typename U, bool b>
  const bool My3_help<T, U, b>::trait;

template<typename T, typename U>
  class My3
  {
  public:
    bool
    f()
    { return My3_help<T, U>::trait; }
  };

#define PTEST(T, U) (__is_base_of(T, U) && f<T, U>() \
                  && My<T, U>().f() && My2<T, U>::trait && My3<T, U>().f())

#define NTEST(T, U) (!__is_base_of(T, U) && !f<T, U>() \
                  && !My<T, U>().f() && !My2<T, U>::trait && !My3<T, U>().f())

int main()
{
  assert (NTEST (int, A1));
  assert (NTEST (A1, void));
  assert (PTEST (A1, A1));
  assert (NTEST (A1*, A1*));
  assert (NTEST (A1&, A1&));
  assert (PTEST (A1, B));
  assert (NTEST (B, A1));
  assert (PTEST (A1, C));
  assert (PTEST (A2, C));
  assert (NTEST (C, A1));
  assert (PTEST (A1, const B));
  assert (NTEST (const B, A1));
  assert (PTEST (A1, volatile C));
  assert (PTEST (volatile A2, const C));
  assert (NTEST (const volatile C, A1));
  assert (NTEST (U, U));

  return 0;
}