public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/43559] New: Overloaded template functions became ambiguous @ 2010-03-28 19:04 sefi at s-e-f-i dot de 2010-03-28 19:28 ` [Bug c++/43559] " paolo dot carlini at oracle dot com ` (5 more replies) 0 siblings, 6 replies; 7+ messages in thread From: sefi at s-e-f-i dot de @ 2010-03-28 19:04 UTC (permalink / raw) To: gcc-bugs The following code used to work with gcc-4.4.3. The Comeau online compiler also accepts it. But with the gcc-4.5 trunk, it is rejected as ambiguous. template<typename T, typename U> void f(U&) { } template<typename T, typename U> void f(T const&) { } int main() { int a; f<int, int const>(a); } This is a reduced test case from boost.phoenix. I'm not completely sure if gcc-4.5 is now right or wrong. Please investigate. -- Summary: Overloaded template functions became ambiguous Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sefi at s-e-f-i dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de @ 2010-03-28 19:28 ` paolo dot carlini at oracle dot com 2010-03-28 19:33 ` schaub-johannes at web dot de ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: paolo dot carlini at oracle dot com @ 2010-03-28 19:28 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from paolo dot carlini at oracle dot com 2010-03-28 19:27 ------- Jason, what do you think? -- paolo dot carlini at oracle dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de 2010-03-28 19:28 ` [Bug c++/43559] " paolo dot carlini at oracle dot com @ 2010-03-28 19:33 ` schaub-johannes at web dot de 2010-03-30 13:47 ` [Bug c++/43559] [4.5 Regression] " rguenth at gcc dot gnu dot org ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: schaub-johannes at web dot de @ 2010-03-28 19:33 UTC (permalink / raw) To: gcc-bugs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 3385 bytes --] ------- Comment #2 from schaub-johannes at web dot de 2010-03-28 19:33 ------- I've done some analysis for this using the argument-deduction during partial ordering rules as clarified by http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#214: template<typename T, typename U> void f(U&) { } // #1 template<typename T, typename U> void f(T const&) { } // #2 4 Each type from the parameter template and the corresponding type from the argument template are used as the types of P and A. Round 1, #1 -> #2: As: (X&) // #1 Ps: (T const&) // #2 Round 2, #2 -> #1: As: (X const&) // #2 Ps: (T&) // #1 If P is a reference type, P is replaced by the type referred to. If A is a reference type, A is replaced by the type referred to. => Round 1, #1 -> #2: As: (X) // #1 Ps: (T const) // #2 Round 2, #2 -> #1: As: (X const) // #2 Ps: (T) // #1 If both P and A were reference types (before being replaced with the type referred to above), determine which of the two types (if any) is more cv-qualified than the other; otherwise the types are considered to be equally cv-qualified for partial ordering purposes. The result of this determination will be used below. => ************* #2 more cv-qualified than #1 If P is a cv-qualified type, P is replaced by the cv-unqualified version of P. If A is a cv-qualified type, A is replaced by the cv-unqualified version of A. Round 1, #1 -> #2: As: (X) // #1 Ps: (T) // #2 Round 2, #2 -> #1: As: (X) // #2 Ps: (T) // #1 Using the resulting types P and A the deduction is then done as described in 14.9.2.5. If deduction succeeds for a given type, the type from the argument template is considered to be at least as specialized as the type from the parameter template. Round 1, T <- X Round 2, T <- X #1.param1 at least as specialized as #2.param1 and vice-versa. If, for a given type, deduction succeeds in both directions (i.e., the types are identical after the transformations above) and if the type from the argument template is more cv-qualified than the type from the parameter template (as described above) that type is considered to be more specialized than the other. Deduction succeeded in both rounds ("types" as in P/A pairs), but #2.param1 was more cv-qualified => #2.param1 more specialized than #1.param1 If for each type being considered a given template is at least as specialized for all types and more specialized for some set of types and the other template is not more specialized for any types or is not at least as specialized for any types, then the given template is more specialized than the other template. #2 is at least as specialized for all types and more specialized for #1.param1 and #1 is not more specialized for any types, so #2 is more specialized than #1. So, i think GCC should choose the one with the f(T const&) because that template is more specialized. Notice that the rules also say In most cases, all template parameters must have values in order for deduction to succeed, but for partial ordering purposes a template parameter may remain without a value provided it is not used in the types being used for partial ordering. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] [4.5 Regression] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de 2010-03-28 19:28 ` [Bug c++/43559] " paolo dot carlini at oracle dot com 2010-03-28 19:33 ` schaub-johannes at web dot de @ 2010-03-30 13:47 ` rguenth at gcc dot gnu dot org 2010-03-30 16:46 ` jason at gcc dot gnu dot org ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: rguenth at gcc dot gnu dot org @ 2010-03-30 13:47 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from rguenth at gcc dot gnu dot org 2010-03-30 13:47 ------- Still unconfirmed, leaving at P3. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] [4.5 Regression] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de ` (2 preceding siblings ...) 2010-03-30 13:47 ` [Bug c++/43559] [4.5 Regression] " rguenth at gcc dot gnu dot org @ 2010-03-30 16:46 ` jason at gcc dot gnu dot org 2010-03-30 19:40 ` jason at gcc dot gnu dot org 2010-03-30 19:47 ` jason at gcc dot gnu dot org 5 siblings, 0 replies; 7+ messages in thread From: jason at gcc dot gnu dot org @ 2010-03-30 16:46 UTC (permalink / raw) To: gcc-bugs ------- Comment #4 from jason at gcc dot gnu dot org 2010-03-30 16:46 ------- Yes, this is a bug. The call to same_type_p in more_specialized_fn is wrong because the two template parms have different indices. -- jason at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org |dot org | Status|UNCONFIRMED |ASSIGNED Ever Confirmed|0 |1 Last reconfirmed|0000-00-00 00:00:00 |2010-03-30 16:46:47 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] [4.5 Regression] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de ` (3 preceding siblings ...) 2010-03-30 16:46 ` jason at gcc dot gnu dot org @ 2010-03-30 19:40 ` jason at gcc dot gnu dot org 2010-03-30 19:47 ` jason at gcc dot gnu dot org 5 siblings, 0 replies; 7+ messages in thread From: jason at gcc dot gnu dot org @ 2010-03-30 19:40 UTC (permalink / raw) To: gcc-bugs ------- Comment #5 from jason at gcc dot gnu dot org 2010-03-30 19:40 ------- Subject: Bug 43559 Author: jason Date: Tue Mar 30 19:39:48 2010 New Revision: 157831 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157831 Log: PR c++/43559 * pt.c (more_specialized_fn): Don't control cv-qualifier check with same_type_p. Added: trunk/gcc/testsuite/g++.dg/template/partial7.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/43559] [4.5 Regression] Overloaded template functions became ambiguous 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de ` (4 preceding siblings ...) 2010-03-30 19:40 ` jason at gcc dot gnu dot org @ 2010-03-30 19:47 ` jason at gcc dot gnu dot org 5 siblings, 0 replies; 7+ messages in thread From: jason at gcc dot gnu dot org @ 2010-03-30 19:47 UTC (permalink / raw) To: gcc-bugs ------- Comment #6 from jason at gcc dot gnu dot org 2010-03-30 19:47 ------- Fixed. -- jason at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43559 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-03-30 19:47 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-03-28 19:04 [Bug c++/43559] New: Overloaded template functions became ambiguous sefi at s-e-f-i dot de 2010-03-28 19:28 ` [Bug c++/43559] " paolo dot carlini at oracle dot com 2010-03-28 19:33 ` schaub-johannes at web dot de 2010-03-30 13:47 ` [Bug c++/43559] [4.5 Regression] " rguenth at gcc dot gnu dot org 2010-03-30 16:46 ` jason at gcc dot gnu dot org 2010-03-30 19:40 ` jason at gcc dot gnu dot org 2010-03-30 19:47 ` jason at gcc dot gnu dot 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).