;
else
{
+ tree old_template = most_general_template (old_decl);
tree new_template = TI_TEMPLATE (new_friend_template_info);
tree new_args = TI_ARGS (new_friend_template_info);
/* Reassign any specializations already in the hash table
to the new more general template, and add the
additional template args. */
- for (t = DECL_TEMPLATE_INSTANTIATIONS (old_decl);
+ for (t = DECL_TEMPLATE_INSTANTIATIONS (old_template);
t != NULL_TREE;
t = TREE_CHAIN (t))
{
decl_specializations->remove_elt (&elt);
- DECL_TI_ARGS (spec)
- = add_outermost_template_args (new_args,
- DECL_TI_ARGS (spec));
+ tree& spec_args = DECL_TI_ARGS (spec);
+ spec_args = add_outermost_template_args
+ (new_args, INNERMOST_TEMPLATE_ARGS (spec_args));
register_specialization
- (spec, new_template, DECL_TI_ARGS (spec), true, 0);
+ (spec, new_template, spec_args, true, 0);
}
- DECL_TEMPLATE_INSTANTIATIONS (old_decl) = NULL_TREE;
+ DECL_TEMPLATE_INSTANTIATIONS (old_template) = NULL_TREE;
}
}
--- /dev/null
+// PR c++/112288
+// { dg-do compile { target c++11 } }
+
+template<class T>
+struct slot {
+ template<class U>
+ friend constexpr bool slot_allocated(slot<T>, U);
+};
+
+template<class T>
+struct allocate_slot {
+ template<class U>
+ friend constexpr bool slot_allocated(slot<T>, U) { return true; }
+};
+
+template<class T, bool = slot_allocated(slot<T>{}, 42)>
+constexpr int next(int) { return 1; }
+
+template<class T>
+constexpr int next(...) { return (allocate_slot<T>{}, 0); }
+
+// slot_allocated<slot<int>, int>() not defined yet
+static_assert(next<int>(0) == 0, "");
+// now it's defined, need to make existing spec point to defn or else ICE
+static_assert(next<int>(0) == 1, "");
--- /dev/null
+// PR c++/112288
+// { dg-do link }
+
+template<class T> struct A;
+template<class T> struct B;
+
+A<int>* a;
+B<int>* b;
+
+template<class T>
+struct B {
+ template<class U>
+ friend int f(A<T>*, B*, U);
+};
+
+template struct B<int>; // f declared
+int n = f(a, b, 0); // f<int> specialized
+
+template<class T>
+struct A {
+ template<class U>
+ friend int f(A*, B<T>*, U) { return 42; }
+};
+
+template struct A<int>; // f defined, need to make existing f<int> point to defn
+int m = f(a, b, 0); // reuses existing specialization f<int>
+
+int main() { }
--- /dev/null
+// PR c++/112288
+// { dg-do link }
+// A version of friend81.C where A and B have a different number of template
+// parameters.
+
+template<class T> struct A;
+template<class T, class = void> struct B;
+
+A<int>* a;
+B<int>* b;
+
+template<class T, class>
+struct B {
+ template<class U>
+ friend int f(A<T>*, B*, U);
+};
+
+template struct B<int>; // f declared
+int n = f(a, b, 0); // f<int> specialized
+
+template<class T>
+struct A {
+ template<class U>
+ friend int f(A*, B<T>*, U) { return 42; }
+};
+
+template struct A<int>; // f defined, need to make existing f<int> point to defn
+int m = f(a, b, 0); // reuses existing specialization f<int>
+
+int main() { }