On Tue, 24 Jan 2023 at 22:47, Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Tue, Jan 24, 2023 at 10:25 PM Jason McKesson via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:

> Because the language says that it is.
>
> The member access works because all member functions defined in the
> class definition are effectively placed after the end of that class
> definition. Therefore, they get to access class members that were not
> yet defined.
>
> Referring to things in a function that haven't been defined yet isn't allowed.


I feel like I'm pointing at water here and saying "water is wet" but
anyway . . . I'll spell it out:

'return_t' can be determined from the return statement, even if the
return statement comes after the first use of 'return_t'.

Uh huh. And what will the compiler do in this case?

auto f() {
   return std::bool_constant<not return_t::value>();
}
 
So when the compiler sees the following:

template<typename T, typename A>
auto Func(T obj0, A obj1)
{
    return_t obj;
    return obj0 + obj1;
}

It picks out the return statement: obj0 + obj1

It wraps it in decltype: decltype(obj0 + obj1)

and then it makes a new type: typedef decltype(obj0 + obj1) return_t;

So here's what the compiler turns it into:

template<typename T, typename A>
auto Func(T obj0, A obj1)
{
    typedef decltype(obj0 + obj1) return_t;
    return_t obj;
    return obj0 + obj1;
}
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals