This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH to add auto return type deduction with -std=c++1y


On Wed, Mar 28, 2012 at 10:51 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Sun, 25 Mar 2012, Marc Glisse wrote:
>
>> - a first goal is simple functions, with a single return statement (which
>> may even often be the only statement).
>
>
> After playing with it a bit, I am not sure how to use it in the simple
> forwarding case:
>
> T f(int);
> auto g(int i){return f(i);}

function call or return value is equivalent to initialization. So, the
deduction works (as it should) as if you wrote

    auto x = f(i);

>
> If T is a reference, this does a copy.
>
> auto&& g(int i){return f(i);}
>
> Now if T is not a reference, this returns a reference to a destroyed
> temporary.
>
> So I am back to writing the following, which is precisely what we never want
> to write:
>
> auto g(int i)->decltype(f(i)){return f(i);}
>
> Maybe having just auto (no auto const&, auto&& and others) without stripping
> cv-ref from it would work better in this case? It would have drawbacks in
> other cases...
>
> I guess the discussion should happen on a different forum once the proposal
> is published...
>
> --
> Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]