Reputation: 757
I know every expression in c++ has a category (prvalue, xvalue, lvalue..) and a type which according to the standard draft, is never of reference type (may be cv qualified if not a prvalue)
5 If an expression initially has the type “reference to T” (8.3.2, 8.5.3), the type is adjusted to T prior to any further analysis. The expression designates the object or function denoted by the reference, and the expression is an lvalue or an xvalue, depending on the expression.
6 If a prvalue initially has the type “cv T,” where T is a cv-unqualified non-class, non-array type, the type of the expression is adjusted to T prior to any further analysis.
Given that decltype has its own set of rules and the auto deduction has a different one as well, when does this “non-reference expression type” matter?
Upvotes: 2
Views: 141
Reputation: 40150
It matters in unevaluated expressions:
typeid
:
typeid(std::cout << 0) == typeid(std::ostream);
// true
noexcept
:
template<class T> void f() noexcept(noexcept(T{}+T{}))
sizeof
(even though sizeof
has a specific rule, non contradicting with the rule for types of full expressions):
sizeof(std::cout << 0);
// the expression returns an std::ostream&, but its type is std::ostream
etc.
Upvotes: 1