[Bug c++/85250] New: Builtin operator overload resolution fails to consider user-defined conversion template
rustamabd at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Apr 6 10:31:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85250
Bug ID: 85250
Summary: Builtin operator overload resolution fails to consider
user-defined conversion template
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rustamabd at gmail dot com
Target Milestone: ---
Consider the following contrived example.
-----------------------------------------------------------
#include <type_traits>
struct A {
template<typename T, typename
std::enable_if<std::is_same<T,int>::value,int>::type = 0>
operator T() { return static_cast<T>(1); }
};
int main() {
int x = 1;
A a;
return x + a;
}
-----------------------------------------------------------
Output from g++:
error: no match for 'operator+' (operand types are 'int' and 'A')
return x + a;
~~^~~
-----------------------------------------------------------
Compiles fine in clang.
-----------------------------------------------------------
A lookup on + should find the built-in int operator+(int&,int) as the only
viable candidate (see [over.match.oper]/6).
That candidate is viable because A can be converted to int via a user-defined
conversion.
If operator int() isn't a template, G++ is able to compile the code.
It's just the conversion function *template* that fails to be considered.
More information about the Gcc-bugs
mailing list