|
| 1 | +// { dg-do run } |
| 2 | +// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=off -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=Ville -Wsuggest-explicit-contract" } |
| 3 | +#include <cassert> |
| 4 | + |
| 5 | +/*missing bits : |
| 6 | + * - virtual destructor |
| 7 | + * - virtual constructors |
| 8 | + */ |
| 9 | + |
| 10 | +bool test(int i){ return true;} |
| 11 | + |
| 12 | +namespace T1{ |
| 13 | +struct Base |
| 14 | +{ |
| 15 | + virtual void f1(int i) pre (test(i)){}; |
| 16 | + virtual void f2(int i) pre (test(i)){}; |
| 17 | + virtual int f3(const int i) post (test(i)){ return i;}; |
| 18 | + virtual void f4(const int i) post (test(i)){}; |
| 19 | + virtual void f5() {}; |
| 20 | + |
| 21 | +}; |
| 22 | + |
| 23 | +struct Child : Base |
| 24 | +{ |
| 25 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 26 | + virtual void f2(int i) pre (test(i)){} |
| 27 | + virtual int f3(const int i) {return i;};// { dg-warning "Function implicitly inherits a contract" } |
| 28 | + void f4(int i){}; // { dg-warning "Function implicitly inherits a contract" } |
| 29 | + virtual void f5(int i) {}; |
| 30 | + virtual void f6(int i) {}; |
| 31 | + |
| 32 | +}; |
| 33 | + |
| 34 | +struct GChild : Child |
| 35 | +{ |
| 36 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 37 | + virtual void f2(int i) pre (test(i)){} |
| 38 | + //virtual int f3(int i) not defined |
| 39 | + void f4(bool b){}; |
| 40 | + virtual void f5(int i) {}; |
| 41 | + |
| 42 | +}; |
| 43 | + |
| 44 | +struct GGChild : GChild |
| 45 | +{ |
| 46 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 47 | + virtual void f2(int i) pre (test(i)){} |
| 48 | + virtual int f3(const int i) { return i; } |
| 49 | + void f4(int i){}; |
| 50 | + virtual void f5(int i) {}; |
| 51 | + |
| 52 | +}; |
| 53 | +}; //namespace T1 |
| 54 | + |
| 55 | +// template base |
| 56 | +namespace T2{ |
| 57 | +template<typename T> |
| 58 | +struct Base |
| 59 | +{ |
| 60 | + virtual void f1(int i) pre (test(i)){}; |
| 61 | + virtual void f2(int i) pre (test(i)){}; |
| 62 | + virtual int f3(const int i) post (r: test(r)){ return i;}; |
| 63 | + virtual void f4(const int i) post (test(i)){}; |
| 64 | + virtual void f5(int i) {}; |
| 65 | + virtual void f6(int i) {}; |
| 66 | + |
| 67 | +}; |
| 68 | + |
| 69 | + |
| 70 | +struct Child : Base<int> |
| 71 | +{ |
| 72 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 73 | + virtual void f2(int i) pre (test(i)){} |
| 74 | + virtual int f3(int i) {return i;};// { dg-warning "Function implicitly inherits a contract" } |
| 75 | + void f4(int i){}; |
| 76 | + virtual void f5(int i) {}; |
| 77 | + virtual void f6(int i) {}; |
| 78 | + |
| 79 | +}; |
| 80 | + |
| 81 | +struct GChild : Child |
| 82 | +{ |
| 83 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 84 | + virtual void f2(int i) pre (test(i)){} |
| 85 | + //virtual int f3(int i) not defined |
| 86 | + void f4(int i){}; |
| 87 | + virtual void f5(int i) {}; |
| 88 | + |
| 89 | +}; |
| 90 | + |
| 91 | +struct GGChild : GChild |
| 92 | +{ |
| 93 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 94 | + virtual void f2(int i) pre (test(i)){} |
| 95 | + virtual int f3(int i) { return i; } |
| 96 | + void f4(int i){}; |
| 97 | + virtual void f5(int i) {}; |
| 98 | + |
| 99 | +}; |
| 100 | + |
| 101 | +}; //namespace T2 |
| 102 | + |
| 103 | + |
| 104 | +// template base |
| 105 | +namespace T3{ |
| 106 | +template<typename T> |
| 107 | +struct BaseT |
| 108 | +{ |
| 109 | + virtual void f1(int i) pre (test(i)){}; |
| 110 | + virtual void f2(int i) pre (test(i)){}; |
| 111 | + virtual int f3(int i) post (r: test(r)){ return i;}; |
| 112 | + virtual void f4(int i) post (test(i)){}; |
| 113 | + virtual void f5(int i) {}; |
| 114 | + virtual void f6(int i) {}; |
| 115 | + |
| 116 | + |
| 117 | +}; |
| 118 | + |
| 119 | +struct Child2 : virtual Base<int> |
| 120 | +{ |
| 121 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 122 | + virtual void f2(int i) pre (test(i)){} |
| 123 | + virtual int f3(int i) {return i;};// { dg-warning "Function implicitly inherits a contract" } |
| 124 | + void f4(int i){}; |
| 125 | + virtual void f5(int i) {}; |
| 126 | + virtual void f6(int i) {}; |
| 127 | + |
| 128 | + virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" } |
| 129 | +}; |
| 130 | + |
| 131 | +struct GChild2 : Child2 |
| 132 | +{ |
| 133 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 134 | + virtual void f2(int i) pre (test(i)){} |
| 135 | + //virtual int f3(int i) not defined |
| 136 | + void f4(int i){}; |
| 137 | + virtual void f5(int i) {}; |
| 138 | + |
| 139 | + virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" } |
| 140 | +}; |
| 141 | + |
| 142 | +struct GGChild2 : GChild2 |
| 143 | +{ |
| 144 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 145 | + virtual void f2(int i) pre (test(i)){} |
| 146 | + virtual int f3(int i) { return i; } |
| 147 | + void f4(int i){}; |
| 148 | + virtual void f5(int i) {}; |
| 149 | + |
| 150 | + virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" } |
| 151 | +}; |
| 152 | + |
| 153 | +}; //namespace T2 |
| 154 | + |
| 155 | +template<typename T> |
| 156 | +struct Child3 : Base<T> |
| 157 | +{ |
| 158 | + virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" } |
| 159 | + virtual void f2(int i) pre (test(i)){} |
| 160 | + virtual int f3(int i) pre (test(i)){}; |
| 161 | + void f4(int i){}; |
| 162 | + virtual void f5(int i) {}; |
| 163 | + |
| 164 | + virtual ~Child3() {}// { dg-warning "Function implicitly inherits a contract" } |
| 165 | +}; |
| 166 | + |
| 167 | +*/ |
| 168 | + |
| 169 | +int main(int, char**) |
| 170 | +{ |
| 171 | + |
| 172 | + { |
| 173 | + T1::Base b; |
| 174 | + T1::Child c; |
| 175 | + T1::GChild gc; |
| 176 | + T1::GGChild gc; |
| 177 | + } |
| 178 | + { |
| 179 | + T2::Base b; |
| 180 | + T2::Child c; |
| 181 | + T2::GChild gc; |
| 182 | + T2::GGChild gc; |
| 183 | + } |
| 184 | + { |
| 185 | + T3::Base b; |
| 186 | + T3::Child c; |
| 187 | + T3::GChild gc; |
| 188 | + T3::GGChild gc; |
| 189 | + } |
| 190 | + |
| 191 | + |
| 192 | + return 0; |
| 193 | +} |
0 commit comments