[llvm] r264314 - [docs] Clarify Error example in Programmer's Manual.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 11:46:50 PDT 2016


On Thu, Mar 24, 2016 at 11:37 AM, Rafael Espíndola <
llvm-commits at lists.llvm.org> wrote:

> So, what I meant in the other "example review" is that while I
> personally like using auto in here, it seems in conflict with the
> current rule:
>
>
> ----------------------------------------------------------------------------
> Don’t “almost always” use auto, but do use auto with initializers
> likecast<Foo>(...) or other places where the type is already obvious
> from the context.


I'd say this fits the "already obvious from context" in this example - the
return type is only a few lines away, the name indicates that it's an error
result & the more details about the type aren't very helpful in this
context "it's an error that's being propagated" - we don't need to know
much more about it.

I don't think this use of auto should be seen as integral to the example -
just appropriate in that context & the use of auto when passing around
errors should be evaluated as usual in a case-by-case basis as per the
style guide.

At least that's my guess/feeling.

- Dave


> Another time when auto works well for these purposes
> is when the type would have been abstracted away anyways, often behind
> a container’s typedef such asstd::vector<T>::iterator.
> -------------------------------------------------------------------
>
> Cheers,
> Rafael
>
>
> On 24 March 2016 at 14:05, Lang Hames via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: lhames
> > Date: Thu Mar 24 13:05:21 2016
> > New Revision: 264314
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264314&view=rev
> > Log:
> > [docs] Clarify Error example in 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=264314&r1=264313&r2=264314&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/docs/ProgrammersManual.rst (original)
> > +++ llvm/trunk/docs/ProgrammersManual.rst Thu Mar 24 13:05:21 2016
> > @@ -361,11 +361,13 @@ success, enabling the following idiom:
> >
> >  .. code-block:: c++
> >
> > -  if (auto Err = mayFail())
> > -    return Err;
> > -
> > -  // Success! We can proceed.
> > +  Error mayFail();
> >
> > +  Error foo() {
> > +    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
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> 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/1d784367/attachment.html>


More information about the llvm-commits mailing list