public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63217] New: template conversion operator returning const reference not used for conversion in some cases
@ 2014-09-10 20:35 rs2740 at gmail dot com
  2014-10-03 12:55 ` [Bug c++/63217] " daniel.kruegler at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: rs2740 at gmail dot com @ 2014-09-10 20:35 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-03  2:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10 20:35 [Bug c++/63217] New: template conversion operator returning const reference not used for conversion in some cases rs2740 at gmail dot com
2014-10-03 12:55 ` [Bug c++/63217] " daniel.kruegler at googlemail dot com
2014-12-13 18:31 ` ville.voutilainen at gmail dot com
2021-08-09 23:10 ` pinskia at gcc dot gnu.org
2021-12-03  2:11 ` pinskia at gcc dot gnu.org
2021-12-03  2:12 ` pinskia at gcc dot gnu.org
2021-12-03  2:18 ` pinskia at gcc dot gnu.org
2021-12-03  2:21 ` pinskia at gcc dot gnu.org
2021-12-03  2:23 ` pinskia at gcc dot gnu.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).