This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16246] New: Incorrect template argument deduction


the code:
-------------------------------------
//#include <algorithm>
namespace std
{
	template<class T> T min(T const&,T const&);
		//declaring min() instead of including <algorithm> to save 
space.
		//this example works in both cases
}

template<unsigned N> 
struct tester
{
	template<class T,unsigned M> 
	void fn( T(&val)[M] )
	{
		std::min(N,M);
		std::min(M,N);
	}
};

int main()
{
	tester<10> t;
	t.fn("1234");
}
-------------------------------------
fails on mingw GCC-3.4.0 with diagnostics:
-------------------------------------
bug2.cxx: In member function `void tester<N>::fn(T (&)[M]) [with T = const 
char, unsigned int M = 5, unsigned int N = 10u]':
bug2.cxx:20:   instantiated from here
bug2.cxx:12: error: no matching function for call to `min(unsigned int, int)'
bug2.cxx:13: error: no matching function for call to `min(int, unsigned int)'
-------------------------------------
"M" deduced to be "int", but it declared as "unsigned" in "template<>" clause

-- 
           Summary: Incorrect template argument deduction
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vassili_bourdo at softhome dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]