|
4366 | 4366 | class X {
|
4367 | 4367 | public:
|
4368 | 4368 | int v() const;
|
4369 |
| - void f() [[expects: x > 0]]; // Ill-formed |
| 4369 | + void f() [[expects: x > 0]]; // error: \tcode{x} is private |
4370 | 4370 | void g() [[expects: v() > 0]]; // OK
|
4371 | 4371 | friend void r(int z) [[expects: z > 0]]; // OK
|
4372 |
| - friend void s(int z) [[expects: z > x]]; // Ill-formed |
| 4372 | + friend void s(int z) [[expects: z > x]]; // error: \tcode{x} is private |
4373 | 4373 | protected:
|
4374 | 4374 | int w();
|
4375 |
| - void h() [[expects: x > 0]]; // Ill-formed |
| 4375 | + void h() [[expects: x > 0]]; // error: \tcode{x} is private |
4376 | 4376 | void i() [[ensures: y > 0]]; // OK
|
4377 | 4377 | void j() [[ensures: w() > 0]]; // OK
|
4378 | 4378 | int y;
|
|
4384 | 4384 | class Y : public X {
|
4385 | 4385 | public:
|
4386 | 4386 | void a() [[expects: v() > 0]]; // OK
|
4387 |
| - void b() [[ensures: w() > 0]]; // Ill-formed |
| 4387 | + void b() [[ensures: w() > 0]]; // error: \tcode{w} is protected |
4388 | 4388 | protected:
|
4389 | 4389 | void c() [[expects: w() > 0]]; // OK
|
4390 | 4390 | };
|
|
4627 | 4627 | int g(int * p)
|
4628 | 4628 | [[ensures r: p != nullptr]]
|
4629 | 4629 | {
|
4630 |
| - *p = 42; // OK, p is not modified |
| 4630 | + *p = 42; // OK, \tcode{p} is not modified |
4631 | 4631 | }
|
4632 | 4632 |
|
4633 | 4633 | int h(int x)
|
|
4644 | 4644 | A function pointer cannot include contract conditions.
|
4645 | 4645 | \begin{example}
|
4646 | 4646 | \begin{codeblock}
|
4647 |
| -typedef int (*fpt)() [[ensures r: r != 0]]; // Ill-formed |
| 4647 | +typedef int (*fpt)() [[ensures r: r != 0]]; // error: contract condition not on a function declaration |
4648 | 4648 |
|
4649 | 4649 | int g(int x)
|
4650 | 4650 | [[expects: x >= 0]]
|
|
4653 | 4653 | return x+1;
|
4654 | 4654 | }
|
4655 | 4655 |
|
4656 |
| -int (*pf)(int) = g; // OK |
4657 |
| -int x = pf(5); // contract conditions of g are checked |
| 4656 | +int (*pf)(int) = g; // OK |
| 4657 | +int x = pf(5); // contract conditions of \tcode{g} are checked |
4658 | 4658 | \end{codeblock}
|
4659 | 4659 | \end{example}
|
4660 | 4660 | \end{note}
|
|
4693 | 4693 | }
|
4694 | 4694 |
|
4695 | 4695 | struct C : A, B {
|
4696 |
| - virtual void g(); // Ill-formed, no diagnostic required |
| 4696 | + virtual void g(); // ill-formed, no diagnostic required |
4697 | 4697 | };
|
4698 | 4698 | \end{codeblock}
|
4699 | 4699 | \end{example}
|
|
0 commit comments