[Bug c++/85695] New: if constexpr misevaluates typedefed type value
msharov at users dot sourceforge.net
gcc-bugzilla@gcc.gnu.org
Tue May 8 14:05:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85695
Bug ID: 85695
Summary: if constexpr misevaluates typedefed type value
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msharov at users dot sourceforge.net
Target Milestone: ---
template <typename T, T v>
struct integral_constant {
using value_type = T;
static constexpr const value_type value = v;
constexpr operator value_type (void) const { return value; }
};
template <typename T> struct is_trivial
: public integral_constant<bool, __is_trivial(T)> {};
template <typename T>
T clone_object (const T& p)
{
if constexpr (is_trivial<T>::value)
return p;
else
return p.clone();
}
int main (void) { return clone_object(0); }
This fails to compile: "error: request for member ‘clone’ in ‘p’". The strange
part is that changing the type of integral_constant::value to T makes it work,
as does using is_trivial<T>() in the conditional, invoking the cast operator.
For some reason, value_type is evaluated differently if it is a variable or
return value, and differently from T.
More information about the Gcc-bugs
mailing list