public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101004] New: SFINAE constrained conversion operator of class template parameter type does not work with built-in arithmetic operators
@ 2021-06-09 21:51 namark at disroot dot org
0 siblings, 0 replies; only message in thread
From: namark at disroot dot org @ 2021-06-09 21:51 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-09 21:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 21:51 [Bug c++/101004] New: SFINAE constrained conversion operator of class template parameter type does not work with built-in arithmetic operators namark at disroot dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).