[llvm] r264135 - [Docs] Clarify boolean conversion for Error and Expected<T> in the Programmer's

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 11:11:28 PDT 2016


 Hi Rafael,

I'd always use auto here, but I agree this example is a bit ambiguous for
the docs. I've added a prototype for mayFail() in r264314.

- Lang.

On Wed, Mar 23, 2016 at 5:28 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> Should we use 'auto' in code that that?
>
> Cheers,
> Rafael
>
>
> On 22 March 2016 at 23:18, Lang Hames via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: lhames
> > Date: Tue Mar 22 22:18:16 2016
> > New Revision: 264135
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264135&view=rev
> > Log:
> > [Docs] Clarify boolean conversion for Error and Expected<T> in the
> Programmer's
> > Manual.
> >
> >
> > Modified:
> >     llvm/trunk/docs/ProgrammersManual.rst
> >
> > Modified: llvm/trunk/docs/ProgrammersManual.rst
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.rst?rev=264135&r1=264134&r2=264135&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/docs/ProgrammersManual.rst (original)
> > +++ llvm/trunk/docs/ProgrammersManual.rst Tue Mar 22 22:18:16 2016
> > @@ -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++
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160324/a92a7850/attachment.html>


More information about the llvm-commits mailing list