[Bug c++/63217] New: template conversion operator returning const reference not used for conversion in some cases
rs2740 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Sep 10 20:35:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63217
Bug ID: 63217
Summary: template conversion operator returning const reference
not used for conversion in some cases
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Minimized repro:
struct foo {
template<class T>
operator const T & () { static T t {}; return t;}
};
int main() {
int t((foo()));
}
g++ complains:
prog.cc: In function 'int main()':
prog.cc:7:18: error: cannot convert 'foo' to 'int' in initialization
int t((foo()));
^
This behavior is consistently reproducible in all versions of g++ I tested.
Both Clang and MSVC 2013 compiles this code without errors.
The template `operator const T&` should have been instantiated with `T = int`
and used for the conversion. Using a non-template `operator const int &`
instead of a template makes the code compile.
More information about the Gcc-bugs
mailing list