This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
template type deduction for non-dependent parameters
- From: gkeating at apple dot com (Geoffrey Keating)
- To: gcc-patches at gcc dot gnu dot org
- Cc: mmitchell at codesourcery dot com
- Date: Sun, 29 May 2005 23:30:04 -0700 (PDT)
- Subject: template type deduction for non-dependent parameters
This patch causes template type deduction to apply even to
non-dependent procedure parameters.
Previously, the comment said that 'Overload resolution will handle
it', which was true up until a few months ago when, as part of
c++/17413, certain error messages were emitted when a function was
selected by template type deduction during overload resolution even if
that function was not actually chosen by overload resolution. Now, we
can't be sloppy about what template functions are passed to overload
resolution; we have to pass exactly those functions the standard says.
The comment also said that infinite recursion could occur. I think
this is a left-over from when we used to fully instantiate templates,
including generating code, without any queuing. Now we delay all
template instantiations until the end of compilation and we have
unit-at-a-time mode. The only infinite recursion I can see would be
if the compiler tried to instantiate a conversion function in the call
to can_convert_arg and somehow ended up back in this code again; but
as far as I can see, that's impossible.
Bootstrapped & tested on powerpc-darwin. I'll wait a while for comments
before committing.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-cp-typedeductionnondep.patch==========
2005-05-29 Geoffrey Keating <geoffk@apple.com>
PR c++/17413
* pt.c (type_unification_real): Apply template type deduction even
to procedure parameters that are not dependent on a template
parameter.
Index: testsuite/ChangeLog
2005-05-29 Geoffrey Keating <geoffk@apple.com>
PR c++/17413
* g++.dg/template/local5.C: New.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.1000
diff -u -p -u -p -r1.1000 pt.c
--- cp/pt.c 27 May 2005 23:17:17 -0000 1.1000
+++ cp/pt.c 30 May 2005 06:19:14 -0000
@@ -9344,17 +9344,12 @@ type_unification_real (tree tparms,
else
type = arg;
- if (strict == DEDUCE_EXACT)
- {
- if (same_type_p (parm, type))
- continue;
- }
- else
- /* It might work; we shouldn't check now, because we might
- get into infinite recursion. Overload resolution will
- handle it. */
+ if (same_type_p (parm, type))
continue;
-
+ if (strict != DEDUCE_EXACT
+ && can_convert_arg (parm, type, TYPE_P (arg) ? NULL_TREE : arg))
+ continue;
+
return 1;
}
Index: testsuite/g++.dg/template/local5.C
===================================================================
RCS file: testsuite/g++.dg/template/local5.C
diff -N testsuite/g++.dg/template/local5.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/template/local5.C 30 May 2005 06:19:42 -0000
@@ -0,0 +1,12 @@
+struct Attribute { };
+
+template <class T> bool operator == (const Attribute &attr, const T &value);
+
+enum {
+ anon = 123
+};
+
+void test(int foo)
+{
+ if (foo == anon) ; /* { dg-bogus "anonymous type" } */
+}
============================================================