+/* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
+ from ATTRIBS that affect type identity, and no others. If any are not
+ applied, set *remove_attributes to true. */
+
+static tree
+apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
+{
+ tree first_ident = NULL_TREE;
+ tree new_attribs = NULL_TREE;
+ tree *p = &new_attribs;
+
+ for (tree a = attribs; a; a = TREE_CHAIN (a))
+ {
+ const attribute_spec *as
+ = lookup_attribute_spec (get_attribute_name (a));
+ if (as && as->affects_type_identity)
+ {
+ if (!first_ident)
+ first_ident = a;
+ else if (first_ident == error_mark_node)
+ {
+ *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
+ p = &TREE_CHAIN (*p);
+ }
+ }
+ else if (first_ident)
+ {
+ for (tree a2 = first_ident; a2; a2 = TREE_CHAIN (a2))
+ {
+ *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
+ p = &TREE_CHAIN (*p);
+ }
+ first_ident = error_mark_node;
+ }
+ }
+ if (first_ident != error_mark_node)
+ new_attribs = first_ident;
+
+ if (first_ident == attribs)
+ /* All attributes affected type identity. */;
+ else
+ *remove_attributes = true;
+
+ return cp_build_type_attribute_variant (result, new_attribs);
+}
+