current_template_parms
= tree_cons (size_int (current_template_depth + 1),
parms, current_template_parms);
+ TEMPLATE_PARMS_CONSTRAINTS (current_template_parms)
+ = TEMPLATE_PARMS_CONSTRAINTS (parmlist);
TEMPLATE_PARMS_FOR_INLINE (current_template_parms) = 1;
begin_scope (TREE_VEC_LENGTH (parms) ? sk_template_parms : sk_template_spec,
DECL_INTERFACE_KNOWN (decl) = 1;
return error_mark_node;
}
+
+ /* Check that the constraints for each enclosing template scope are
+ consistent with the original declarations. */
+ if (flag_concepts)
+ {
+ tree decl_parms = DECL_TEMPLATE_PARMS (tmpl);
+ tree scope_parms = current_template_parms;
+ if (PRIMARY_TEMPLATE_P (tmpl))
+ {
+ decl_parms = TREE_CHAIN (decl_parms);
+ scope_parms = TREE_CHAIN (scope_parms);
+ }
+ while (decl_parms)
+ {
+ if (!template_requirements_equivalent_p (decl_parms, scope_parms))
+ {
+ error ("redeclaration of %qD with different constraints",
+ TPARMS_PRIMARY_TEMPLATE (TREE_VALUE (decl_parms)));
+ break;
+ }
+ decl_parms = TREE_CHAIN (decl_parms);
+ scope_parms = TREE_CHAIN (scope_parms);
+ }
+ }
}
gcc_checking_assert (!tmpl || DECL_TEMPLATE_RESULT (tmpl) == decl);
--- /dev/null
+// PR c++/96830
+// { dg-do compile { target c++20 } }
+
+template<class T> concept C = true;
+
+template<C T> requires true
+struct A {
+ void f();
+ template<class U> void g();
+
+ struct B;
+ template<class U> struct C;
+
+ static int D;
+ template<class U> static int E;
+};
+
+template<C T>
+void A<T>::f() { } // { dg-error "different constraints" }
+
+template<class T> requires true
+template<class U>
+void A<T>::g() { } // { dg-error "different constraints" }
+
+template<C T> requires (!!true)
+struct A<T>::B { }; // { dg-error "different constraints" }
+
+template<class T> requires true
+template<class U>
+struct A<T>::C { }; // { dg-error "different constraints" }
+
+template<C T>
+int A<T>::D = 0; // { dg-error "different constraints" }
+
+template<class T> requires true
+template<class U>
+int A<T>::E = 0; // { dg-error "different constraints" }
--- /dev/null
+// PR c++/96830
+// A valid version of concepts-class5.C.
+// { dg-do compile { target c++20 } }
+
+template<class T> concept C = true;
+
+template<C T> requires true
+struct A {
+ void f();
+ template<class U> void g();
+
+ struct B;
+ template<class U> struct C;
+
+ static int D;
+ template<class U> static int E;
+};
+
+template<C T> requires true
+void A<T>::f() { }
+
+template<C T> requires true
+template<class U>
+void A<T>::g() { }
+
+template<C T> requires true
+struct A<T>::B { };
+
+template<C T> requires true
+template<class U>
+struct A<T>::C { };
+
+template<C T> requires true
+int A<T>::D = 0;
+
+template<C T> requires true
+template<class U>
+int A<T>::E = 0;