mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-18 18:42:46 +02:00
[docs] Simplify some language for Error/cantFail in the programmer's manual.
llvm-svn: 301773
This commit is contained in:
parent
30cdb2efea
commit
6372ad3026
@ -776,22 +776,21 @@ readability.
|
|||||||
Using cantFail to simplify safe callsites
|
Using cantFail to simplify safe callsites
|
||||||
"""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
Some functions may only fail for a subset of their inputs. For such functions
|
Some functions may only fail for a subset of their inputs, so calls using known
|
||||||
call-sites using known-safe inputs can assume that the result will be a success
|
safe inputs can be assumed to succeed.
|
||||||
value.
|
|
||||||
|
|
||||||
The cantFail functions encapsulate this by wrapping an assertion that their
|
The cantFail functions encapsulate this by wrapping an assertion that their
|
||||||
argument is a success value and, in the case of Expected<T>, unwrapping the
|
argument is a success value and, in the case of Expected<T>, unwrapping the
|
||||||
T value from the Expected<T> argument:
|
T value:
|
||||||
|
|
||||||
.. code-block:: c++
|
.. code-block:: c++
|
||||||
|
|
||||||
Error mayFail(int X);
|
Error onlyFailsForSomeXValues(int X);
|
||||||
Expected<int> mayFail2(int X);
|
Expected<int> onlyFailsForSomeXValues2(int X);
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
cantFail(mayFail(KnownSafeValue));
|
cantFail(onlyFailsForSomeXValues(KnownSafeValue));
|
||||||
int Y = cantFail(mayFail2(KnownSafeValue));
|
int Y = cantFail(onlyFailsForSomeXValues2(KnownSafeValue));
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,8 +800,8 @@ terminate the program on an error input, cantFile simply asserts that the result
|
|||||||
is success. In debug builds this will result in an assertion failure if an error
|
is success. In debug builds this will result in an assertion failure if an error
|
||||||
is encountered. In release builds the behavior of cantFail for failure values is
|
is encountered. In release builds the behavior of cantFail for failure values is
|
||||||
undefined. As such, care must be taken in the use of cantFail: clients must be
|
undefined. As such, care must be taken in the use of cantFail: clients must be
|
||||||
certain that a cantFail wrapped call really can not fail under any
|
certain that a cantFail wrapped call really can not fail with the given
|
||||||
circumstances.
|
arguments.
|
||||||
|
|
||||||
Use of the cantFail functions should be rare in library code, but they are
|
Use of the cantFail functions should be rare in library code, but they are
|
||||||
likely to be of more use in tool and unit-test code where inputs and/or
|
likely to be of more use in tool and unit-test code where inputs and/or
|
||||||
|
Loading…
Reference in New Issue
Block a user