Triggered by this question, I was wondering if, this is allowed:
template <typename T>
T foo(){return T{};}
struct bar {};
int main()
{
bar a = foo<decltype(a)>();
}
Compilers I tried took it without complaints, but I am not sure if this is really legal or if I am missing any pitfalls (and it looks weird to use the type of a during its declaration).
For background: in the linked question OP wants to avoid auto and spelling out the type (here it is bar, SomeComplexTypeAndNotAuto in that question) twice at the same time, hence they use a (unused) parameter to deduce T. I didn't like misusing a parameter merely to deduce the type so my first idea was decltype.