public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "namark at disroot dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101004] New: SFINAE constrained conversion operator of class template parameter type does not work with built-in arithmetic operators Date: Wed, 09 Jun 2021 21:51:56 +0000 [thread overview] Message-ID: <bug-101004-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
reply other threads:[~2021-06-09 21:51 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-101004-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).