decltype( constexpr variable)
问题 Why decltype of constexpr variable is failed ? #include <cstdint> #include <type_traits> constexpr uint16_t foo(){ return 0;} constexpr auto cv = foo(); auto v = foo(); static_assert( std::is_same< uint16_t, decltype(cv)>::value, "!"); // failed static_assert( std::is_same< uint16_t, decltype(v) >::value, "!"); // success 回答1: decltype(entity) specifies the declared type of the entity specified by this expression. Due to the constexpr, ( A constexpr specifier used in an object declaration