[Bug c++/93870] New: User-defined conversion function not working in evaluation of template argument
o_kniemeyer at maxon dot net
gcc-bugzilla@gcc.gnu.org
Fri Feb 21 14:45:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93870
Bug ID: 93870
Summary: User-defined conversion function not working in
evaluation of template argument
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: o_kniemeyer at maxon dot net
Target Milestone: ---
According to gcc.godbolt.org GCC 7.1 up to 9.2 fail to compile this piece of
code:
template <typename ENUM> struct EnumWrapper
{
ENUM value;
constexpr operator ENUM() const
{
return value;
}
};
enum E : int
{
V
};
constexpr EnumWrapper<E> operator ~(E a)
{
return {E(~int(a))};
}
template <E X> struct R
{
static void Func();
};
template <E X> struct S : R<~X>
{
};
void Test()
{
S<E::V>::Func();
}
The can't evaluate the template argument ~X for R:
<source>: In instantiation of 'struct S<(E)0>':
<source>:32:12: required from here
<source>:26:31: error: taking address of temporary [-fpermissive]
template <E X> struct S : R<~X>
^
<source>:26:31: error: no matching function for call to
'EnumWrapper<E>::operator E(EnumWrapper<E>*)'
<source>:5:12: note: candidate: constexpr EnumWrapper<ENUM>::operator ENUM()
const [with ENUM = E]
constexpr operator ENUM() const
^~~~~~~~
<source>:5:12: note: candidate expects 0 arguments, 1 provided
<source>: In function 'void Test()':
<source>:32:14: error: 'Func' is not a member of 'S<(E)0>'
S<E::V>::Func();
^~~~
All other compiler are fine. A workaround is to convert to E explicitly by
writing R<E(~X)>.
More information about the Gcc-bugs
mailing list