Bug 51613 - [4.4/4.5/4.6/4.7 Regression] Ambiguous function template instantiations as template argument are not rejected
Summary: [4.4/4.5/4.6/4.7 Regression] Ambiguous function template instantiations as te...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.2
: P2 normal
Target Milestone: 4.7.0
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid, wrong-code
Depends on:
Blocks:
 
Reported: 2011-12-18 22:15 UTC by PkmX
Modified: 2012-01-11 20:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.5
Known to fail: 4.4.5, 4.7.0
Last reconfirmed: 2011-12-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PkmX 2011-12-18 22:15:12 UTC
In the book "C++ Templates - The Complete Guide" section 8.3, the following code snippet is given:

template<typename F, typename T>
void apply(F f, T t)
{
    f(t);
}

template<typename T>
void multi(T)
{
}

template<typename T>
void multi(T*)
{
}

int main()
{
    apply(&multi<int>, 7);

    return 0;
}

My understanding is that &multi<int> here instantiates two functions of types void (*)(int) and void (*)(int*) with no ways to disambiguate and therefore F cannot be deducted. However, gcc currently deducts F as void (*)(int) and ultimately calls multi(int). This is the same case for gcc 4.4.3, gcc 4.6.2, gcc 4.7.0 20111112 snapshot and probably other versions.
Comment 1 Andrew Pinski 2011-12-29 06:07:16 UTC
Confirmed.
Comment 2 Jason Merrill 2012-01-11 16:47:05 UTC
Author: jason
Date: Wed Jan 11 16:46:57 2012
New Revision: 183099

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183099
Log:
	PR c++/51613
	* pt.c (resolve_overloaded_unification): Compare types with
	same_type_p, not decls_match.

Added:
    trunk/gcc/testsuite/g++.dg/template/explicit-args5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2012-01-11 20:39:45 UTC
Fixed for 4.7.  Not backporting fixes for invalid code bugs.