mardi 17 avril 2018

std::declval and unevaluated expressions

With reference to the following example in Proposing Standard Library Support for the C++ Detection Idiom:

// primary template handles types that do not support pre-increment
template< class, class = void_t<> >
struct
has_pre_increment_member : false_type { };

// specialization recognizes types that do support pre-increment
template< class T >
struct
has_pre_increment_member<T, void_t<decltype( ++declval<T&>() )>> : true_type { };

how does the expression decltype( ++declval<T&>() ) classify as unevaluated?

In the above, assuming declval() returns T& as discussed in Is there a reason declval returns add_rvalue_reference instead of add_lvalue_reference , doesn't the result of the expression ++T& (resulting from ++declval<T&>) become odr-used as opposed to unevaluated? As per ODR-use:

a reference is odr-used if it is used and its referent is not known at compile time;

In the above case, isn't the reference both used and its referent not known at compile time as well?

Aucun commentaire:

Enregistrer un commentaire