File: contracts-redecl2.C

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (149 lines) | stat: -rw-r--r-- 3,029 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// generic error tests for generalized contract redecls
// { dg-do compile }
// { dg-options "-std=c++2a -fcontracts" }

// allowed to repeat contracts or omit them
int g0(int a) [[ pre: a > 0 ]];
int g0(int a) [[ pre: a > 0 ]];

int g1(int a) [[ pre: a > 0 ]];
int g1(int a);

// allowed to add from none if generalized redecl is on (by default)
int g2(int a);
int g2(int a) [[ pre: a > 0 ]];

// can add to non-virtual methods
struct G0
{
  int f(int a);
};

int G0::f(int a) [[ pre: a > 0 ]]
{
  return -a;
}

struct G1
{
  int f(int a);
};

int G1::f(int a) [[ pre: a > 0 ]];

int G1::f(int a)
{
  return -a;
}

// allowed to redeclare even without contracts
struct G2
{
  int f(int a);
};

int G2::f(int a);


int f0(int a) [[ pre: a > 0 ]];
int f0(int a) [[ pre: a > 0 ]] [[ pre: a > 10 ]]; // { dg-error "different number of contracts" }

int f1(int a) [[ pre: a > 0 ]];
int f1(int a) [[ pre: a < 0 ]]; // { dg-error "mismatched contract" }

int f2(int a) { return a; }
int f2(int a) [[ pre: a < 0 ]]; // { dg-error "cannot add contracts after definition" }

struct Base
{
  virtual int f(int a) [[ pre: a > 0 ]];
};

struct Child : Base
{
  int f(int a) [[ pre: a < 0 ]]; // { dg-error "mismatched contract" }
};

// the initial decl of a guarded member must appear inside the class
struct F2
{
  int f(int a);
};

int F2::g(int a) [[ pre: a > 0 ]]; // { dg-error "no declaration matches" }
// FIXME if we move F2 down then a different error makes F2 undeclared

struct F0
{
  virtual int f(int a);
};

int F0::f(int a); // { dg-error "declaration.*is not definition" }

struct F1
{
  virtual int f(int a);
};

int F1::f(int a) [[ pre: a > 0 ]] // { dg-error "cannot add" }
{
  return -a;
}

// cannot "re"declare members of a forward declared class
struct F2;
int F2::test(); // { dg-error "no declaration matches" }
int F2::test2() [[ pre: true ]]; // { dg-error "no declaration matches" }

// can only redeclare member functions
struct F3
{
  int x;
  typedef int my_int;

  struct Inner0;
  struct Inner1;
  enum my_enum0; // { dg-error "use of enum.*without previous decl" }
  enum my_enum1 { E1, E2 };

  int test0();
  int test1();
  int test2();
};

int F3::x{-1}; // { dg-error "is not a static data member" }
typedef double F3::my_int; // { dg-error "typedef name may not be a nested-name-specifier" }
struct F3::Inner0; // { dg-warning "declaration.*does not declare anything" }

struct F3::Inner1 { };

enum F3::my_enum1 { E0, E1, END }; // { dg-error "multiple definition" }

struct F4
{
  int test0();

  int F3::test0() [[ pre: true ]]; // { dg-error "cannot declare member function" }
  friend int F3::test1();
  friend int F3::test2();
};
int F3::test2() [[ pre: true ]] { return -1; }

void dummy0()
{
  int F4::test0() [[ pre: true ]]; // { dg-error "qualified-id in declaration" }
}

namespace ns0
{
  typedef int value;
  struct X
  {
    int test1(value);
    typedef double value;
    int test2(value);
  };
  int X::test1(value); // { dg-error "no declaration matches" }
  int X::test2(value);
}