public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yaghmour.shafik at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/62110] New: Attempting to use template conversion operator in a contextual conversion
Date: Tue, 12 Aug 2014 19:27:00 -0000	[thread overview]
Message-ID: <bug-62110-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62110

            Bug ID: 62110
           Summary: Attempting to use template conversion operator in a
                    contextual conversion
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yaghmour.shafik at gmail dot com

Given the following code:

class Var
{
public:

    operator int () const
    { return 0; }

    template <typename T>
    operator T () const
    { return T(); }

};

int main()
{
    Var v;
    switch (v)
    { }
}

gcc 4.9 produces the following error:

main.cpp: In function 'int main()':

main.cpp:17:14: error: default type conversion can't deduce template argument
for 'template<class T> Var::operator T() const'
     switch (v)
              ^

using the following command line options:

  -std=c++11 -Wall -Wextra -Wconversion -pedantic

Using -std=c++1y also produces the same error.

while clang 3.4 does not produce any errors. As far as I can tell clang is
correct here for C++1y and is probably correct for C++11 although that may
depend on whether you consider  N3323: "A Proposal to Tweak Certain C++
Contextual Conversions" to be a fix for C++11 or part of C++1y. 

N3323 is incorporated in N3485 which I consider to be C++11 with fixes but
perhaps that is an incorrect interpretation. Based on this assumption then if
we look at section 6.4.2 it says:

The condition shall be of integral type, enumeration type, or class type. If of
class type, the condition is contextually implicitly converted (Clause 4) to an
integral or enumeration type.

and this would force us to use section 4 paragraph 5 which does not allow or
overload resolution making int conversion the only one available for this
context.

If N3323 is not part of C++11 then it seems unclear to me whether the template
conversion function should be considered or not.

This bug report comes the following Stackoverflow question:

http://stackoverflow.com/questions/25047109/classes-with-both-template-and-non-template-conversion-operators-in-the-conditio


             reply	other threads:[~2014-08-12 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 19:27 yaghmour.shafik at gmail dot com [this message]
2014-08-12 20:31 ` [Bug c++/62110] " redi at gcc dot gnu.org
2014-08-12 23:27 ` rs2740 at gmail dot com
2014-12-14  0:28 ` ville.voutilainen at gmail dot com

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-62110-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: link
Be 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).