|
| 1 | +// generic assert contract parsing checks |
| 2 | +// check omitted, 'default', 'audit', and 'axiom' contract levels parse |
| 3 | +// check that all concrete semantics parse |
| 4 | +// check omitted, '%default' contract roles parse |
| 5 | +// ensure that an invalid contract level 'invalid' errors |
| 6 | +// ensure that a predicate referencing an undefined variable errors |
| 7 | +// ensure that a missing colon after contract level errors |
| 8 | +// ensure that an invalid contract role 'invalid' errors |
| 9 | +// ensure that a missing colon after contract role errors |
| 10 | +// { dg-do compile } |
| 11 | +// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=P2900R13" } |
| 12 | + |
| 13 | +struct B{ |
| 14 | + |
| 15 | + virtual void f() post(true) = 0; |
| 16 | + |
| 17 | +}; |
| 18 | + |
| 19 | +struct D : B { |
| 20 | + void f() override post(true) = 0; |
| 21 | +}; |
| 22 | + |
| 23 | +// non attribute contracts come after override. |
| 24 | +struct E : D { |
| 25 | + void f() post(true) override; // { dg-error "expected" } |
| 26 | + // { dg-error "override" "" { target *-*-* } .-1 } |
| 27 | +}; |
| 28 | + |
| 29 | + |
| 30 | +namespace other{ |
| 31 | + |
| 32 | + |
| 33 | + struct X |
| 34 | + { |
| 35 | + virtual void f(int x) pre(x >= 0); |
| 36 | + }; |
| 37 | + |
| 38 | + struct Y : X |
| 39 | + { |
| 40 | + void f(int x) override pre(x >= 0); |
| 41 | + }; |
| 42 | + |
| 43 | + struct Y2 : X |
| 44 | + { |
| 45 | + void f(int x) pre(x >= 0) override; // { dg-error "expected .;. at end of member declaration|does not name a type" } |
| 46 | + }; |
| 47 | + |
| 48 | + struct Y3 : X |
| 49 | + { |
| 50 | + void f(int x) pre(x >= 0) override pre(x >= 0); // { dg-error "expected .;. at end of member declaration|does not name a type" } |
| 51 | + }; |
| 52 | + |
| 53 | + struct X2 |
| 54 | + { |
| 55 | + virtual void f(int x) pre(x >= 0); |
| 56 | + }; |
| 57 | + |
| 58 | + struct X3 |
| 59 | + { |
| 60 | + virtual void f(int x) final pre(x >= 0); |
| 61 | + }; |
| 62 | + |
| 63 | + struct X4 |
| 64 | + { |
| 65 | + virtual void f(int x) pre(x >= 0) final; // { dg-error "expected .;. at end of member declaration|does not name a type" } |
| 66 | + }; |
| 67 | + |
| 68 | + struct X5 |
| 69 | + { |
| 70 | + virtual void f(int x) pre(x >= 0) final pre(x >= 0); // { dg-error "expected .;. at end of member declaration|does not name a type" } |
| 71 | + }; |
| 72 | + |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +namespace parsing_virtual_test { |
| 77 | + struct A { |
| 78 | + virtual void f(int i) |
| 79 | + pre(i >= 0); |
| 80 | + }; |
| 81 | + |
| 82 | + struct B : A { |
| 83 | + void f(int i) override final |
| 84 | + pre(i >= 0); |
| 85 | + }; |
| 86 | + |
| 87 | + struct C : A { |
| 88 | + void f(int i) override |
| 89 | + pre(i >= 0) = 0; |
| 90 | + }; |
| 91 | +} |
| 92 | + |
| 93 | +namespace parsing_default_delete_pure_test { |
| 94 | + const bool a = true, b = true, c = true; |
| 95 | + |
| 96 | + struct X { |
| 97 | + X() pre(a) = default; |
| 98 | + X(const X&) pre(b) = delete; |
| 99 | + virtual void f() pre(c) = 0; |
| 100 | + }; |
| 101 | +} |
| 102 | + |
| 103 | +int main() |
| 104 | +{ |
| 105 | +} |
0 commit comments