|
8348 | 8348 | The predicate of a contract condition has the same semantic restrictions
|
8349 | 8349 | as if it appeared as the first \grammarterm{expression-statement}
|
8350 | 8350 | in the body of the function it applies to.
|
8351 |
| -Additional access restrictions apply to names appearing in |
8352 |
| -a contract condition of a member function of class \tcode{C}: |
8353 |
| -\begin{itemize} |
8354 |
| -\item Friendship is not considered\iref{class.friend}. |
8355 |
| -\item For a contract condition of a public member function, |
8356 |
| -no member of \tcode{C} or of an enclosing class of \tcode{C} is accessible |
8357 |
| -unless it is a public member of \tcode{C}, |
8358 |
| -or a member of a base class |
8359 |
| -accessible as a public member of \tcode{C}\iref{class.access.base}. |
8360 |
| -\item For a contract condition of a protected member function, |
8361 |
| -no member of \tcode{C} or of an enclosing class of \tcode{C} is accessible |
8362 |
| -unless it is a public or protected member of \tcode{C}, |
8363 |
| -or a member of a base class |
8364 |
| -accessible as a public or protected member of \tcode{C}. |
8365 |
| -\end{itemize} |
8366 |
| -For names appearing in a contract condition of a non-member function, |
8367 |
| -friendship is not considered. |
8368 |
| -\begin{example} |
8369 |
| -\begin{codeblock} |
8370 |
| -class X { |
8371 |
| -public: |
8372 |
| - int v() const; |
8373 |
| - void f() [[expects: x > 0]]; // error: \tcode{x} is private |
8374 |
| - void g() [[expects: v() > 0]]; // OK |
8375 |
| - friend void r(int z) [[expects: z > 0]]; // OK |
8376 |
| - friend void s(int z) [[expects: z > x]]; // error: \tcode{x} is private |
8377 |
| -protected: |
8378 |
| - int w(); |
8379 |
| - void h() [[expects: x > 0]]; // error: \tcode{x} is private |
8380 |
| - void i() [[ensures: y > 0]]; // OK |
8381 |
| - void j() [[ensures: w() > 0]]; // OK |
8382 |
| - int y; |
8383 |
| -private: |
8384 |
| - void k() [[expects: x > 0]]; // OK |
8385 |
| - int x; |
8386 |
| -}; |
8387 |
| - |
8388 |
| -class Y : public X { |
8389 |
| -public: |
8390 |
| - void a() [[expects: v() > 0]]; // OK |
8391 |
| - void b() [[ensures: w() > 0]]; // error: \tcode{w} is protected |
8392 |
| -protected: |
8393 |
| - void c() [[expects: w() > 0]]; // OK |
8394 |
| -}; |
8395 |
| -\end{codeblock} |
8396 |
| -\end{example} |
8397 | 8351 |
|
8398 | 8352 | \pnum
|
8399 | 8353 | A precondition is checked by evaluating its predicate
|
|
0 commit comments