FreeBSD/contrib/gcc/cp/decl.c
/* Create a VAR_DECL named NAME with the indicated TYPE.

   If SCOPE is non-NULL, it is the class type or namespace containing
   the variable.  If SCOPE is NULL, the variable should is created in
   the innermost enclosings scope.  */
Create a VAR_DECL named NAME with the indicated TYPE.
If SCOPE is non-NULL, it is the class type or namespace containing
the variable.  If SCOPE is NULL, the variable should is created in
the innermost enclosings scope.
Create a VAR_DECL named NAME with the indicated TYPE . If SCOPE is non - NULL it is the class type or namespace containing the variable . If SCOPE is NULL the variable should is created in the innermost enclosings scope .
static tree
grokvardecl (tree type,
	     tree name,
	     const cp_decl_specifier_seq *declspecs,
	     int initialized,
	     int constp,
	     tree scope)
{
  tree decl;
  tree explicit_scope;
  gcc_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE);
  explicit_scope = scope;
  if (!scope)
    {
      if (declspecs->storage_class == sc_extern)
	scope = current_namespace;
      else if (!at_function_scope_p ())
	scope = current_scope ();
    }
  if (scope
      && (
	  (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
	  || (TREE_CODE (scope) == NAMESPACE_DECL
	      && current_lang_name != lang_name_cplusplus)
	  || TYPE_P (scope)))
    decl = build_lang_decl (VAR_DECL, name, type);
  else
    decl = build_decl (VAR_DECL, name, type);
  if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
    set_decl_namespace (decl, explicit_scope, 0);
  else
    DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
  if (declspecs->storage_class == sc_extern)
    {
      DECL_THIS_EXTERN (decl) = 1;
      DECL_EXTERNAL (decl) = !initialized;
    }
  if (DECL_CLASS_SCOPE_P (decl))
    {
      set_linkage_for_static_data_member (decl);
      DECL_EXTERNAL (decl) = 0;
      check_class_member_definition_namespace (decl);
    }
  else if (toplevel_bindings_p ())
    {
      TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
			    && (DECL_THIS_EXTERN (decl) || ! constp));
      TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
    }
  else
    {
      TREE_STATIC (decl) = declspecs->storage_class == sc_static;
      TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
    }
  if (declspecs->specs[(int)ds_thread])
    {
      if (targetm.have_tls)
	DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
      else
	error ("thread-local storage not supported for this target");
    }
  if (TREE_PUBLIC (decl))
    {
      tree t = no_linkage_check (TREE_TYPE (decl), false);
      if (t)
	{
	  if (TYPE_ANONYMOUS_P (t))
	    {
	      if (DECL_EXTERN_C_P (decl))
		  ;
	      else
		{
		  warning (0, "non-local variable %q#D uses anonymous type",
			   decl);
		  if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
		    warning (0, "%q+#D does not refer to the unqualified "
			     "type, so it is not used for linkage",
			     TYPE_NAME (t));
		}
	    }
	  else
	    warning (0, "non-local variable %q#D uses local type %qT", decl, t);
	}
    }
  else
    DECL_INTERFACE_KNOWN (decl) = 1;
  return decl;
}
static tree grokvardecl ( tree type , tree name , const cp_decl_specifier_seq * declspecs , int initialized , int constp , tree scope ) { tree decl ; tree explicit_scope ; gcc_assert ( ! name || TREE_CODE ( name ) == IDENTIFIER_NODE ) ; explicit_scope = scope ; if ( ! scope ) { if ( declspecs -> storage_class == sc_extern ) scope = current_namespace ; else if ( ! at_function_scope_p ( ) ) scope = current_scope ( ) ; } if ( scope && ( ( TREE_CODE ( scope ) == NAMESPACE_DECL && processing_template_decl ) || ( TREE_CODE ( scope ) == NAMESPACE_DECL && current_lang_name != lang_name_cplusplus ) || TYPE_P ( scope ) ) ) decl = build_lang_decl ( VAR_DECL , name , type ) ; else decl = build_decl ( VAR_DECL , name , type ) ; if ( explicit_scope && TREE_CODE ( explicit_scope ) == NAMESPACE_DECL ) set_decl_namespace ( decl , explicit_scope , 0 ) ; else DECL_CONTEXT ( decl ) = FROB_CONTEXT ( scope ) ; if ( declspecs -> storage_class == sc_extern ) { DECL_THIS_EXTERN ( decl ) = 1 ; DECL_EXTERNAL ( decl ) = ! initialized ; } if ( DECL_CLASS_SCOPE_P ( decl ) ) { set_linkage_for_static_data_member ( decl ) ; DECL_EXTERNAL ( decl ) = 0 ; check_class_member_definition_namespace ( decl ) ; } else if ( toplevel_bindings_p ( ) ) { TREE_PUBLIC ( decl ) = ( declspecs -> storage_class != sc_static && ( DECL_THIS_EXTERN ( decl ) || ! constp ) ) ; TREE_STATIC ( decl ) = ! DECL_EXTERNAL ( decl ) ; } else { TREE_STATIC ( decl ) = declspecs -> storage_class == sc_static ; TREE_PUBLIC ( decl ) = DECL_EXTERNAL ( decl ) ; } if ( declspecs -> specs [ ( int ) ds_thread ] ) { if ( targetm . have_tls ) DECL_TLS_MODEL ( decl ) = decl_default_tls_model ( decl ) ; else error ( " " ) ; } if ( TREE_PUBLIC ( decl ) ) { tree t = no_linkage_check ( TREE_TYPE ( decl ) , false ) ; if ( t ) { if ( TYPE_ANONYMOUS_P ( t ) ) { if ( DECL_EXTERN_C_P ( decl ) ) ; else { warning ( 0 , " " , decl ) ; if ( DECL_ORIGINAL_TYPE ( TYPE_NAME ( t ) ) ) warning ( 0 , " " " " , TYPE_NAME ( t ) ) ; } } else warning ( 0 , " " , decl , t ) ; } } else DECL_INTERFACE_KNOWN ( decl ) = 1 ; return decl ; }
Create a VAR_DECL named NAME with the indicated TYPE.
Create a VAR_DECL named NAME with the indicated TYPE .
/* Compute the scope in which to place the variable, but remember
     whether or not that scope was explicitly specified by the user.   */ /* An explicit "extern" specifier indicates a namespace-scope
	 variable.  */ /* If the variable is a namespace-scope variable declared in a
	     template, we need DECL_LANG_SPECIFIC.  */ /* Similarly for namespace-scope variables with language linkage
	     other than C++.  */ /* Similarly for static data members.  */ /* This function is only called with out-of-class definitions.  */ /* At top level, either `static' or no s.c. makes a definition
     (perhaps tentative), and absence of `static' makes it public.  */ /* Not at top level, only `static' makes a static definition.  */ /* A mere warning is sure to result in improper semantics
	   at runtime.  Don't bother to allow this to compile.  */ /* [basic.link]: A name with no linkage (notably, the name of a class
	 or enumeration declared in a local scope) shall not be used to
	 declare an entity with linkage.

	 Only check this for public decls for now.  */ /*relaxed_p=*/ /* Allow this; it's pretty common in C.  */ /* DRs 132, 319 and 389 seem to indicate types with
		     no linkage can only be used to declare extern "C"
		     entities.  Since it's not always an error in the
		     ISO C++ 90 Standard, we only issue a warning.  */