FreeBSD/contrib/gcc/cp/name-lookup.c
/* BINDING records an existing declaration for a name in the current scope.
   But, DECL is another declaration for that same identifier in the
   same scope.  This is the `struct stat' hack whereby a non-typedef
   class name or enum-name can be bound at the same level as some other
   kind of entity.
   3.3.7/1

     A class name (9.1) or enumeration name (7.2) can be hidden by the
     name of an object, function, or enumerator declared in the same scope.
     If a class or enumeration name and an object, function, or enumerator
     are declared in the same scope (in any order) with the same name, the
     class or enumeration name is hidden wherever the object, function, or
     enumerator name is visible.

   It's the responsibility of the caller to check that
   inserting this name is valid here.  Returns nonzero if the new binding
   was successful.  */
BINDING records an existing declaration for a name in the current scope.
But, DECL is another declaration for that same identifier in the
same scope.  This is the `struct stat' hack whereby a non-typedef
class name or enum-name can be bound at the same level as some other
kind of entity.

A class name (9.1) or enumeration name (7.2) can be hidden by the
name of an object, function, or enumerator declared in the same scope.
If a class or enumeration name and an object, function, or enumerator
are declared in the same scope (in any order) with the same name, the
class or enumeration name is hidden wherever the object, function, or
enumerator name is visible.

It's the responsibility of the caller to check that
inserting this name is valid here.  Returns nonzero if the new binding
was successful.
BINDING records an existing declaration for a name in the current scope . But DECL is another declaration for that same identifier in the same scope . This is the ` struct stat ' hack whereby a non - typedef class name or enum - name can be bound at the same level as some other kind of entity . A class name ( 9 . 1 ) or enumeration name ( 7 . 2 ) can be hidden by the name of an object function or enumerator declared in the same scope . If a class or enumeration name and an object function or enumerator are declared in the same scope ( in any order ) with the same name the class or enumeration name is hidden wherever the object function or enumerator name is visible . It ' s the responsibility of the caller to check that inserting this name is valid here . Returns nonzero if the new binding was successful .
static bool
supplement_binding (cxx_binding *binding, tree decl)
{
  tree bval = binding->value;
  bool ok = true;
  timevar_push (TV_NAME_LOOKUP);
  if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
    binding->type = decl;
  else if (
	   !bval
	   || bval == error_mark_node
	   || (TREE_CODE (bval) == FUNCTION_DECL
	       && DECL_ANTICIPATED (bval)
	       && !DECL_HIDDEN_FRIEND_P (bval)))
    binding->value = decl;
  else if (TREE_CODE (bval) == TYPE_DECL && DECL_ARTIFICIAL (bval))
    {
      binding->type = bval;
      binding->value = decl;
      binding->value_is_inherited = false;
    }
  else if (TREE_CODE (bval) == TYPE_DECL
	   && TREE_CODE (decl) == TYPE_DECL
	   && DECL_NAME (decl) == DECL_NAME (bval)
	   && binding->scope->kind != sk_class
	   && (same_type_p (TREE_TYPE (decl), TREE_TYPE (bval))
	       || uses_template_parms (TREE_TYPE (decl))
	       || uses_template_parms (TREE_TYPE (bval))))
    ok = false;
  else if (TREE_CODE (decl) == VAR_DECL && TREE_CODE (bval) == VAR_DECL
	   && DECL_EXTERNAL (decl) && DECL_EXTERNAL (bval)
	   && !DECL_CLASS_SCOPE_P (decl))
    {
      duplicate_decls (decl, binding->value, false);
      ok = false;
    }
  else if (TREE_CODE (decl) == NAMESPACE_DECL
	   && TREE_CODE (bval) == NAMESPACE_DECL
	   && DECL_NAMESPACE_ALIAS (decl)
	   && DECL_NAMESPACE_ALIAS (bval)
	   && ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl))
    ok = false;
  else
    {
      error ("declaration of %q#D", decl);
      error ("conflicts with previous declaration %q+#D", bval);
      ok = false;
    }
  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
}
static bool supplement_binding ( cxx_binding * binding , tree decl ) { tree bval = binding -> value ; bool ok = true ; timevar_push ( TV_NAME_LOOKUP ) ; if ( TREE_CODE ( decl ) == TYPE_DECL && DECL_ARTIFICIAL ( decl ) ) binding -> type = decl ; else if ( ! bval || bval == error_mark_node || ( TREE_CODE ( bval ) == FUNCTION_DECL && DECL_ANTICIPATED ( bval ) && ! DECL_HIDDEN_FRIEND_P ( bval ) ) ) binding -> value = decl ; else if ( TREE_CODE ( bval ) == TYPE_DECL && DECL_ARTIFICIAL ( bval ) ) { binding -> type = bval ; binding -> value = decl ; binding -> value_is_inherited = false ; } else if ( TREE_CODE ( bval ) == TYPE_DECL && TREE_CODE ( decl ) == TYPE_DECL && DECL_NAME ( decl ) == DECL_NAME ( bval ) && binding -> scope -> kind != sk_class && ( same_type_p ( TREE_TYPE ( decl ) , TREE_TYPE ( bval ) ) || uses_template_parms ( TREE_TYPE ( decl ) ) || uses_template_parms ( TREE_TYPE ( bval ) ) ) ) ok = false ; else if ( TREE_CODE ( decl ) == VAR_DECL && TREE_CODE ( bval ) == VAR_DECL && DECL_EXTERNAL ( decl ) && DECL_EXTERNAL ( bval ) && ! DECL_CLASS_SCOPE_P ( decl ) ) { duplicate_decls ( decl , binding -> value , false ) ; ok = false ; } else if ( TREE_CODE ( decl ) == NAMESPACE_DECL && TREE_CODE ( bval ) == NAMESPACE_DECL && DECL_NAMESPACE_ALIAS ( decl ) && DECL_NAMESPACE_ALIAS ( bval ) && ORIGINAL_NAMESPACE ( bval ) == ORIGINAL_NAMESPACE ( decl ) ) ok = false ; else { error ( " " , decl ) ; error ( " " , bval ) ; ok = false ; } POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , ok ) ; }
BINDING records an existing declaration for a name in the current scope.
BINDING records an existing declaration for a name in the current scope .
/* The new name is the type name.  */ /* BVAL is null when push_class_level_binding moves an
	      inherited type-binding out of the way to make room for a
	      new value binding.  */ /* BVAL is error_mark_node when DECL's name has been used
	      in a non-class scope prior declaration.  In that case,
	      we should have already issued a diagnostic; for graceful
	      error recovery purpose, pretend this was the intended
	      declaration for that name.  */ /* If BVAL is anticipated but has not yet been declared,
	      pretend it is not there at all.  */ /* The old binding was a type name.  It was placed in
	 VALUE field because it was thought, at the point it was
	 declared, to be the only entity with such a name.  Move the
	 type name into the type slot; it is now hidden by the new
	 binding.  */ /* If either type involves template parameters, we must
		  wait until instantiation.  */ /* We have two typedef-names, both naming the same type to have
       the same name.  In general, this is OK because of:

	 [dcl.typedef]

	 In a given scope, a typedef specifier can be used to redefine
	 the name of any type declared in that scope to refer to the
	 type to which it already refers.

       However, in class scopes, this rule does not apply due to the
       stricter language in [class.mem] prohibiting redeclarations of
       members.  */ /* There can be two block-scope declarations of the same variable,
     so long as they are `extern' declarations.  However, there cannot
     be two declarations of the same static data member:

       [class.mem]

       A member shall not be declared twice in the
       member-specification.  */ /*newdecl_is_friend=*/ /* [namespace.alias]

      In a declarative region, a namespace-alias-definition can be
      used to redefine a namespace-alias declared in that declarative
      region to refer only to the namespace to which it already
      refers.  */