static void unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr) { DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2); DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1); if (TREE_CODE (expr) == VAR_DECL) { DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3); } if (TREE_CODE (expr) == FUNCTION_DECL) { DECL_FINAL_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_CXX_CONSTRUCTOR_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_CXX_DESTRUCTOR_P (expr) = (unsigned) bp_unpack_value (bp, 1); } if (VAR_OR_FUNCTION_DECL_P (expr)) { priority_type p; p = (priority_type) bp_unpack_var_len_unsigned (bp); SET_DECL_INIT_PRIORITY (expr, p); } }
static void pack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr) { bp_pack_value (bp, DECL_COMMON (expr), 1); bp_pack_value (bp, DECL_DLLIMPORT_P (expr), 1); bp_pack_value (bp, DECL_WEAK (expr), 1); bp_pack_value (bp, DECL_SEEN_IN_BIND_EXPR_P (expr), 1); bp_pack_value (bp, DECL_COMDAT (expr), 1); bp_pack_value (bp, DECL_VISIBILITY (expr), 2); bp_pack_value (bp, DECL_VISIBILITY_SPECIFIED (expr), 1); if (TREE_CODE (expr) == VAR_DECL) { bp_pack_value (bp, DECL_HARD_REGISTER (expr), 1); /* DECL_IN_TEXT_SECTION is set during final asm output only. */ bp_pack_value (bp, DECL_IN_CONSTANT_POOL (expr), 1); } if (TREE_CODE (expr) == FUNCTION_DECL) { bp_pack_value (bp, DECL_FINAL_P (expr), 1); bp_pack_value (bp, DECL_CXX_CONSTRUCTOR_P (expr), 1); bp_pack_value (bp, DECL_CXX_DESTRUCTOR_P (expr), 1); } }
static void unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr) { DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2); DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1); if (TREE_CODE (expr) == VAR_DECL) { DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1); } if (TREE_CODE (expr) == FUNCTION_DECL) { DECL_FINAL_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_CXX_CONSTRUCTOR_P (expr) = (unsigned) bp_unpack_value (bp, 1); DECL_CXX_DESTRUCTOR_P (expr) = (unsigned) bp_unpack_value (bp, 1); } }
tree do_friend (tree ctype, tree declarator, tree decl, tree attrlist, enum overload_flags flags, bool funcdef_flag) { gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); gcc_assert (!ctype || MAYBE_CLASS_TYPE_P (ctype)); /* Every decl that gets here is a friend of something. */ DECL_FRIEND_P (decl) = 1; if (DECL_OVERRIDE_P (decl) || DECL_FINAL_P (decl)) error ("friend declaration %qD may not have virt-specifiers", decl); /* Unfortunately, we have to handle attributes here. Normally we would handle them in start_decl_1, but since this is a friend decl start_decl_1 never gets to see it. */ /* Set attributes here so if duplicate decl, will have proper attributes. */ cplus_decl_attributes (&decl, attrlist, 0); if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) { declarator = TREE_OPERAND (declarator, 0); if (!identifier_p (declarator)) declarator = OVL_NAME (declarator); } if (ctype) { /* CLASS_TEMPLATE_DEPTH counts the number of template headers for the enclosing class. FRIEND_DEPTH counts the number of template headers used for this friend declaration. TEMPLATE_MEMBER_P is true if a template header in FRIEND_DEPTH is intended for DECLARATOR. For example, the code template <class T> struct A { template <class U> struct B { template <class V> template <class W> friend void C<V>::f(W); }; }; will eventually give the following results 1. CLASS_TEMPLATE_DEPTH equals 2 (for `T' and `U'). 2. FRIEND_DEPTH equals 2 (for `V' and `W'). 3. TEMPLATE_MEMBER_P is true (for `W'). */ int class_template_depth = template_class_depth (current_class_type); int friend_depth = processing_template_decl - class_template_depth; /* We will figure this out later. */ bool template_member_p = false; tree cname = TYPE_NAME (ctype); if (TREE_CODE (cname) == TYPE_DECL) cname = DECL_NAME (cname); /* A method friend. */ if (flags == NO_SPECIAL && declarator == cname) DECL_CXX_CONSTRUCTOR_P (decl) = 1; grokclassfn (ctype, decl, flags); if (friend_depth) { if (!uses_template_parms_level (ctype, class_template_depth + friend_depth)) template_member_p = true; } /* A nested class may declare a member of an enclosing class to be a friend, so we do lookup here even if CTYPE is in the process of being defined. */ if (class_template_depth || COMPLETE_OR_OPEN_TYPE_P (ctype)) { if (DECL_TEMPLATE_INFO (decl)) /* DECL is a template specialization. No need to build a new TEMPLATE_DECL. */ ; else if (class_template_depth) /* We rely on tsubst_friend_function to check the validity of the declaration later. */ decl = push_template_decl_real (decl, /*is_friend=*/true); else decl = check_classfn (ctype, decl, template_member_p ? current_template_parms : NULL_TREE); if ((template_member_p /* Always pull out the TEMPLATE_DECL if we have a friend template in a class template so that it gets tsubsted properly later on (59956). tsubst_friend_function knows how to tell this apart from a member template. */ || (class_template_depth && friend_depth)) && decl && TREE_CODE (decl) == FUNCTION_DECL) decl = DECL_TI_TEMPLATE (decl); if (decl) add_friend (current_class_type, decl, /*complain=*/true); } else error ("member %qD declared as friend before type %qT defined", decl, ctype); } /* A global friend. @@ or possibly a friend from a base class ?!? */ else if (TREE_CODE (decl) == FUNCTION_DECL) { int is_friend_template = PROCESSING_REAL_TEMPLATE_DECL_P (); /* Friends must all go through the overload machinery, even though they may not technically be overloaded. Note that because classes all wind up being top-level in their scope, their friend wind up in top-level scope as well. */ if (funcdef_flag) SET_DECL_FRIEND_CONTEXT (decl, current_class_type); if (! DECL_USE_TEMPLATE (decl)) { /* We must check whether the decl refers to template arguments before push_template_decl_real adds a reference to the containing template class. */ int warn = (warn_nontemplate_friend && ! funcdef_flag && ! is_friend_template && current_template_parms && uses_template_parms (decl)); if (is_friend_template || template_class_depth (current_class_type) != 0) /* We can't call pushdecl for a template class, since in general, such a declaration depends on template parameters. Instead, we call pushdecl when the class is instantiated. */ decl = push_template_decl_real (decl, /*is_friend=*/true); else if (current_function_decl) /* pushdecl will check there's a local decl already. */ decl = pushdecl (decl, /*is_friend=*/true); else { /* We can't use pushdecl, as we might be in a template class specialization, and pushdecl will insert an unqualified friend decl into the template parameter scope, rather than the namespace containing it. */ tree ns = decl_namespace_context (decl); push_nested_namespace (ns); decl = pushdecl_namespace_level (decl, /*is_friend=*/true); pop_nested_namespace (ns); } if (warn) { static int explained; bool warned; warned = warning (OPT_Wnon_template_friend, "friend declaration " "%q#D declares a non-template function", decl); if (! explained && warned) { inform (input_location, "(if this is not what you intended, make sure " "the function template has already been declared " "and add <> after the function name here) "); explained = 1; } } } if (decl == error_mark_node) return error_mark_node; add_friend (current_class_type, is_friend_template ? DECL_TI_TEMPLATE (decl) : decl, /*complain=*/true); DECL_FRIEND_P (decl) = 1; } return decl; }