c++ - Ternary operator '?:' deduces incorrect type in GCC versions pre 4.9.0? -
the following code demonstrates gcc issue (versions < 4.9.0) ternary operator:
static_assert(std::is_same<int, decltype(true ? std::declval<int>() : std::declval<int>())>::value, "succeeds on gcc < 4.9.0"); static_assert(std::is_same<int&&, decltype(true ? std::declval<int>() : std::declval<int>())>::value, "succeeds on gcc >= 4.9.0"); the 2nd line correct implementation (true ? int&& : int&&) should deduce int&& not int.
this can demonstrated via godbolt's compiler explorer
going matt godbolt's compiler explorer, gcc seems change mind on assert fire after version 4.9.0. appears bug fixed time ago.
note declval() defined as
template<class t> typename std::add_rvalue_reference<t>::type declval() noexcept; so expect return type of declval<int>() int&&.
Comments
Post a Comment