This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63217] New: template conversion operator returning const reference not used for conversion in some cases
- From: "rs2740 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 10 Sep 2014 20:35:45 +0000
- Subject: [Bug c++/63217] New: template conversion operator returning const reference not used for conversion in some cases
- Auto-submitted: auto-generated
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.