https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101004
Bug ID: 101004
Summary: SFINAE constrained conversion operator of class
template parameter type does not work with built-in
arithmetic operators
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: namark at disroot dot org
Target Milestone: ---
I believe the following code should be valid, but gcc rejects it (version
10.2.0 on my machine, but also all versions I could try on godbolt.org)
#include <type_traits>
template <typename T, std::size_t S>
class One
{
public:
template <std::size_t SS = S, std::enable_if_t<SS == 1>* = nullptr>
operator T() const { return 1; }
};
int main()
{
return 1 - One<int,1>{}; // no match for operator-
}
The implicit conversion seems to work fine in general with initialization,
assignment or user defined operators/functions, but not with the built-in
arithmetic or comparison operators. Removing the SFINAE constraint fixes it.
Changing the conversion operator type from T to int also fixes it. That is,
either of those is fine on its own, but together they cause this strange
behavior.