public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/47765] Wrong template deduction
Date: Thu, 08 Sep 2011 16:22:00 -0000	[thread overview]
Message-ID: <bug-47765-4-0czsdA1IcP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47765-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47765

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-09-08
     Ever Confirmed|0                           |1

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-08 16:15:24 UTC ---
14.8.2/6: At certain points in the template argument deduction process it is
necessary to take a function type that makes use of template parameters and
replace those template parameters with the corresponding template arguments.
This is done at the beginning of template argument deduction when any
explicitly specified template arguments are substituted into the function type,
and again at the end of template argument deduction when any template arguments
that were deduced or obtained from default arguments are substituted.

So, when we start to try to evaluate b.foo<char>, we substitute 'char' for T in
both templates, so they become

        template<typename T2>
        void foo(const A<char>& r) {}

        void foo(const B<char>& r) {}

14.8.1/6: Implicit conversions (Clause 4) will be performed on a function
argument to convert it to the type of the corresponding function parameter if
the parameter type contains no template-parameters that participate in template
argument deduction. [ Note: Template parameters do not participate in template
argument deduction if they are explicitly specified.

So we no longer do deduction on the first parameter, but rather check for a
conversion.  What is unclear in the standard is when exactly the conversion
should happen.  Currently G++ and EDG seem to check for a conversion during
argument deduction, which leads to instantiation of A<char> and thus the error
you see.  But another reasonable interpretation would be to skip the parameter
during deduction and then let normal overload resolution check for the
conversion; in that case deduction would fail for the first foo and so we never
check the conversion, so we don't try to instantiate A<char>.  clang accepts
this testcase, so it seems likely that this is what they are doing.


  parent reply	other threads:[~2011-09-08 16:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16 12:32 [Bug c++/47765] New: " dk_mipt at mail dot ru
2011-09-08  9:22 ` [Bug c++/47765] " daniel.kruegler at googlemail dot com
2011-09-08 10:52 ` paolo.carlini at oracle dot com
2011-09-08 16:22 ` jason at gcc dot gnu.org [this message]
2011-09-08 17:05 ` daniel.kruegler at googlemail dot com
2011-09-08 19:23 ` jason at gcc dot gnu.org
2011-09-08 19:46 ` jason at gcc dot gnu.org
2013-05-25  8:51 ` paolo.carlini at oracle dot com
2013-05-25  9:19 ` daniel.kruegler at googlemail dot com
2013-05-25 11:07 ` [Bug c++/47765] [Core/1391] " paolo.carlini at oracle dot com
2015-03-20 16:57 ` paolo.carlini at oracle dot com
2020-05-08 15:38 ` mpolacek at gcc dot gnu.org

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-47765-4-0czsdA1IcP@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).