aboutsummaryrefslogtreecommitdiff
path: root/llvm/docs/ProgrammersManual.rst
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2016-03-23 03:18:16 +0000
committerLang Hames <lhames@gmail.com>2016-03-23 03:18:16 +0000
commita0f517fc1596b25bba11cfd6a73f54aabec4546c (patch)
treecb6a4ba445e38458297f3a39367325aa31a942b0 /llvm/docs/ProgrammersManual.rst
parent7cd8e65187565b931c986fa9e725a1e5abe0dcf7 (diff)
downloadllvm-a0f517fc1596b25bba11cfd6a73f54aabec4546c.zip
llvm-a0f517fc1596b25bba11cfd6a73f54aabec4546c.tar.gz
llvm-a0f517fc1596b25bba11cfd6a73f54aabec4546c.tar.bz2
[Docs] Clarify boolean conversion for Error and Expected<T> in the Programmer's
Manual. llvm-svn: 264135
Diffstat (limited to 'llvm/docs/ProgrammersManual.rst')
-rw-r--r--llvm/docs/ProgrammersManual.rst20
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index 1258ad6..5ad5113 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -356,12 +356,24 @@ that inherits from the ErrorInfo utility:
return Error::success();
}
+Error values can be implicitly converted to bool: true for error, false for
+success, enabling the following idiom:
+
+.. code-block::
+
+ if (auto Err = mayFail())
+ return Err;
+
+ // Success! We can proceed.
+
+
For functions that can fail but need to return a value the ``Expected<T>``
utility can be used. Values of this type can be constructed with either a
-``T``, or a ``Error``. Values are implicitly convertible to boolean: true
-for success, false for error. If success, the ``T`` value can be accessed via
-the dereference operator. If failure, the ``Error`` value can be extracted
-using the ``takeError()`` method:
+``T``, or a ``Error``. Expected<T> values are also implicitly convertible to
+boolean, but with the opposite convention to Error: true for success, false for
+error. If success, the ``T`` value can be accessed via the dereference operator.
+If failure, the ``Error`` value can be extracted using the ``takeError()``
+method. Idiomatic usage looks like:
.. code-block:: c++