Skip to content

Commit 47668f2

Browse files
author
Robert Marsh
committed
C++/Docs: move controls predicate to top of file
1 parent 62c73a5 commit 47668f2

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

docs/language/learn-ql/cpp/guards.rst

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ The guards library (defined in ``semmle.code.cpp.controlflow.Guards``) provides
1616
}
1717
return 0;
1818
19+
20+
The ``controls`` predicate
21+
------------------------------------------------
22+
The ``controls`` predicate helps determine which blocks are only run when the ``GuardCondition`` evaluates a certain way. ``guard.controls(block, testIsTrue)`` holds if ``block`` is only entered if the value of this condition is ``testIsTrue``.
23+
24+
In the following code sample, the call to ``isValid`` controls the calls to ``performAction`` and ``logFailure`` but not the return statement.
25+
26+
.. code:: cpp
27+
28+
if(isValid(accessToken)) {
29+
performAction();
30+
succeeded = 1;
31+
} else {
32+
logFailure();
33+
succeeded = 0;
34+
}
35+
return succeeded;
36+
1937
The ``ensuresEq`` and ``ensuresLt`` predicates
2038
----------------------------------------------
2139
The ``ensuresEq`` and ``ensuresLt`` predicates are the main way of determining what, if any, guarantees the ``GuardCondition`` provides for a given basic block.
@@ -35,19 +53,3 @@ The ``comparesEq`` and ``comparesLt`` predicates help determine if the ``GuardCo
3553

3654
``comparesLt(left, right, k, isLessThan, testIsTrue)`` holds if ``left < right + k`` evaluates to ``isLessThan`` when the expression evaluates to ``testIsTrue``.
3755

38-
The ``controls`` predicate
39-
------------------------------------------------
40-
The ``controls`` predicate helps determine which blocks are only run when the ``GuardCondition`` evaluates a certain way. ``guard.controls(block, testIsTrue)`` holds if ``block`` is only entered if the value of this condition is ``testIsTrue``.
41-
42-
In the following code sample, the call to ``isValid`` controls the calls to ``performAction`` and ``logFailure`` but not the return statement.
43-
44-
.. code:: cpp
45-
46-
if(isValid(accessToken)) {
47-
performAction();
48-
succeeded = 1;
49-
} else {
50-
logFailure();
51-
succeeded = 0;
52-
}
53-
return succeeded;

0 commit comments

Comments
 (0)