16246 – [3.3/3.4/4.0 regression] Incorrect template argument deduction (original) (raw)

| Description Vasili Burdo 2004-06-28 14🔞59 UTC the code: ------------------------------------- //#include namespace std { template T min(T const&,T const&); //declaring min() instead of including to save space. //this example works in both cases } template 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::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 Comment 1 Drea Pinski 2004-06-28 16:25:12 UTC Confirmed. Comment 2 Wolfgang Bangerth 2004-06-28 17:09:11 UTC Confirmed indeed. This is a rather peculiar failure: ---------------- template void foo (T, T); template <unsigned N, unsigned M> int bar( const char(&val)[M] ) { foo (N,M); } int i = bar<10>("1234"); ---------------- g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc x.cc: In function `int bar(const char (&)[M]) [with unsigned int N = 10u, unsigned int M = 5]': x.cc:9: instantiated from here x.cc:6: error: no matching function for call to `foo(unsigned int, int)' Note that both N and M are declared to be of type unsigned. However, only N is explicitly specified and M is deduced. From the error message, we see that M is assumed to be unsigned, but the value given in the template parameter list doesn't have the 'u' suffix, so it looks like as if gcc knows that the type is unsigned, but that the node in which the actual value is stored is a signed integer. This mismatch then causes the failure of not finding an instance of foo(). This used to work in 2.95, so is a regression. W. Comment 3 Mark Mitchell 2004-08-18 01:48:49 UTC Working on a fix. Comment 6 Mark Mitchell 2004-08-18 03:00:35 UTC Fixed in GCC 3.4.2. Comment 7 Gabriel Dos Reis 2004-08-29 14:54:51 UTC Subject: Re: [3.3/3.4/3.5 regression] Incorrect template argument deduction "cvs-commit at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: | Subject: Bug 16246 | | CVSROOT: /cvs/gcc | Module name: gcc | Branch: gcc-3_4-branch | Changes by: mmitchel@gcc.gnu.org 2004-08-18 02:59:58 Will not fix this in 3.3.x series -- even though we have a patch for 3.4.x. -- Gaby | | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ----------------- | ---------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |