{
if (nt == ot)
return 1;
+ if (nt == NULL_TREE || ot == NULL_TREE)
+ return false;
if (TREE_CODE (nt) == TREE_VEC)
/* For member templates */
/* In C++0x, it's possible to have a function template whose type depends
on itself recursively. This is most obvious with decltype, but can also
occur with enumeration scope (c++/48969). So we need to catch infinite
- recursion and reject the substitution at deduction time.
+ recursion and reject the substitution at deduction time; this function
+ will return error_mark_node for any repeated substitution.
+
+ This also catches excessive recursion such as when f<N> depends on
+ f<N-1> across all integers, and returns error_mark_node for all the
+ substitutions back up to the initial one.
+
+ This is, of course, not reentrant.
Use of a VEC here is O(n^2) in the depth of function template argument
deduction substitution, but using a hash table creates a lot of constant
static tree
deduction_tsubst_fntype (tree fn, tree targs)
{
+ static bool excessive_deduction_depth;
+
unsigned i;
spec_entry **slot;
spec_entry *p;
/* If we've created a hash table, look there. */
if (current_deduction_htab)
{
+ if (htab_elements (current_deduction_htab)
+ > (unsigned) max_tinst_depth)
+ {
+ /* Trying to recurse across all integers or some such. */
+ excessive_deduction_depth = true;
+ return error_mark_node;
+ }
+
hash = hash_specialization (&elt);
slot = (spec_entry **)
htab_find_slot_with_hash (current_deduction_htab, &elt, hash, INSERT);
r = error_mark_node;
VEC_pop (spec_entry, current_deduction_vec);
}
+ if (excessive_deduction_depth)
+ {
+ r = error_mark_node;
+ if (htab_elements (current_deduction_htab) == 0)
+ /* Reset once we're all the way out. */
+ excessive_deduction_depth = false;
+ }
return r;
}
--- /dev/null
+// PR c++/44175
+// { dg-options -std=c++0x }
+
+template <bool, class T> struct enable_if { };
+template <class T> struct enable_if <true, T> { typedef T type; };
+
+template <class F, int N>
+void ft (F f, typename enable_if<N!=0, int>::type) {}
+
+template< class F, int N >
+decltype(ft<F, N-1> (F(), 0))
+ft (F f, typename enable_if<N==0, int>::type) {}
+
+int main() {
+ ft<struct a*, 2> (0, 0);
+}
--- /dev/null
+// PR c++/44175
+// { dg-options -std=c++0x }
+
+template <bool, class T> struct enable_if { };
+template <class T> struct enable_if <true, T> { typedef T type; };
+
+template <int x>
+typename enable_if<x==0,int>::type
+ft() {}
+
+template<class F, int N>
+decltype (ft<F> (F()))
+ft() {}
+
+int main() {
+ ft<struct a*, 0>(); // { dg-error "no match" }
+}
+
+// { dg-prune-output "note" }