In [dcl.spec] :
For an expression e, the type denoted by decltype(e) is defined as
follows:
if e is an unparenthesized id-expression naming an lvalue or reference introduced from the identifier-list of a decomposition
declaration, decltype(e) is the referenced type as given in the
specification of the decomposition declaration ([dcl.decomp]);
otherwise, if e is an unparenthesized id-expression or an unparenthesized class member access ([expr.ref]), decltype(e) is the
type of the entity named by e. If there is no such entity, or if e
names a set of overloaded functions, the program is ill-formed;
otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e;
otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;
otherwise, decltype(e) is the type of e.
The operand of the decltype specifier is an unevaluated operand
(Clause [expr]).
(Emphasis mine)
So your foo(int{ 13 })
is never evaluated.
std::type_info::name()
isn't guaranteed to give anything reliable. Does it give anything else in other cases? – Lorolatype_info
from the question. Hopefully this helps clarify the issue. This is a question aboutdecltype
and what it's requiring, I was just trying to usetype_info
to demonstrate the question. – Allerasdecltype
doesn't really need the full function definition to know the resulting type. (See). So there is no reason to compile anything other than the prototype. But I don't have a standard quote. – Lorolasizeof(decltype(expression))
seems a little redundant. – Consumablestd::is_same
. I just wanted a quick and dirty condition for the static assert. – Lorolasizeof(expression)
would be sufficient. – Consumable