OSDN Git Service

Revert:
[pf3gnuchains/gcc-fork.git] / gcc / cp / lex.c
index 2975399..d10fa2e 100644 (file)
@@ -1,6 +1,6 @@
 /* Separate lexical analyzer for GNU C++.
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -36,29 +36,21 @@ Boston, MA 02111-1307, USA.  */
 #include "c-pragma.h"
 #include "toplev.h"
 #include "output.h"
-#include "ggc.h"
 #include "tm_p.h"
 #include "timevar.h"
-#include "diagnostic.h"
 
-#ifdef MULTIBYTE_CHARS
-#include "mbchar.h"
-#include <locale.h>
-#endif
-
-static int interface_strcmp PARAMS ((const char *));
-static void init_cp_pragma PARAMS ((void));
+static int interface_strcmp (const char *);
+static void init_cp_pragma (void);
 
-static tree parse_strconst_pragma PARAMS ((const char *, int));
-static void handle_pragma_vtable PARAMS ((cpp_reader *));
-static void handle_pragma_unit PARAMS ((cpp_reader *));
-static void handle_pragma_interface PARAMS ((cpp_reader *));
-static void handle_pragma_implementation PARAMS ((cpp_reader *));
-static void handle_pragma_java_exceptions PARAMS ((cpp_reader *));
+static tree parse_strconst_pragma (const char *, int);
+static void handle_pragma_vtable (cpp_reader *);
+static void handle_pragma_unit (cpp_reader *);
+static void handle_pragma_interface (cpp_reader *);
+static void handle_pragma_implementation (cpp_reader *);
+static void handle_pragma_java_exceptions (cpp_reader *);
 
-static int is_global PARAMS ((tree));
-static void init_operators PARAMS ((void));
-static void copy_lang_type PARAMS ((tree));
+static void init_operators (void);
+static void copy_lang_type (tree);
 
 /* A constraint that can be tested at compile time.  */
 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
@@ -100,8 +92,7 @@ static struct impl_files *impl_file_chain;
    and whose type is the modifier list.  */
 
 tree
-make_pointer_declarator (cv_qualifiers, target)
-     tree cv_qualifiers, target;
+make_pointer_declarator (tree cv_qualifiers, tree target)
 {
   if (target && TREE_CODE (target) == IDENTIFIER_NODE
       && ANON_AGGRNAME_P (target))
@@ -120,8 +111,7 @@ make_pointer_declarator (cv_qualifiers, target)
    and whose type is the modifier list.  */
 
 tree
-make_reference_declarator (cv_qualifiers, target)
-     tree cv_qualifiers, target;
+make_reference_declarator (tree cv_qualifiers, tree target)
 {
   target = build_nt (ADDR_EXPR, target);
   TREE_TYPE (target) = cv_qualifiers;
@@ -129,8 +119,8 @@ make_reference_declarator (cv_qualifiers, target)
 }
 
 tree
-make_call_declarator (target, parms, cv_qualifiers, exception_specification)
-     tree target, parms, cv_qualifiers, exception_specification;
+make_call_declarator (tree target, tree parms, tree cv_qualifiers, 
+                      tree exception_specification)
 {
   target = build_nt (CALL_EXPR, target,
                     tree_cons (parms, cv_qualifiers, NULL_TREE),
@@ -142,8 +132,8 @@ make_call_declarator (target, parms, cv_qualifiers, exception_specification)
 }
 
 void
-set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
-     tree call_declarator, cv_qualifiers, exception_specification;
+set_quals_and_spec (tree call_declarator, tree cv_qualifiers, 
+                    tree exception_specification)
 {
   CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
   CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
@@ -155,24 +145,8 @@ int interface_unknown;             /* whether or not we know this class
                                   to behave according to #pragma interface.  */
 
 \f
-/* Initialization before switch parsing.  */
-void
-cxx_init_options ()
-{
-  c_common_init_options (clk_cplusplus);
-
-  /* Default exceptions on.  */
-  flag_exceptions = 1;
-  /* By default wrap lines at 80 characters.  Is getenv ("COLUMNS")
-     preferable?  */
-  diagnostic_line_cutoff (global_dc) = 80;
-  /* By default, emit location information once for every
-     diagnostic message.  */
-  diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
-}
-
 void
-cxx_finish ()
+cxx_finish (void)
 {
   c_common_finish ();
 }
@@ -190,7 +164,7 @@ operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
 #undef DEF_OPERATOR
 
 static void
-init_operators ()
+init_operators (void)
 {
   tree identifier;
   char buffer[256];
@@ -231,8 +205,6 @@ init_operators ()
   operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
   operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
   operator_name_info [(int) ABS_EXPR].name = "abs";
-  operator_name_info [(int) FFS_EXPR].name = "ffs";
-  operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
   operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
   operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
   operator_name_info [(int) IN_EXPR].name = "in";
@@ -259,7 +231,7 @@ init_operators ()
 struct resword
 {
   const char *const word;
-  const ENUM_BITFIELD(rid) rid : 16;
+  ENUM_BITFIELD(rid) const rid : 16;
   const unsigned int disable   : 16;
 };
 
@@ -281,6 +253,7 @@ static const struct resword reswords[] =
   { "__asm__",         RID_ASM,        0 },
   { "__attribute",     RID_ATTRIBUTE,  0 },
   { "__attribute__",   RID_ATTRIBUTE,  0 },
+  { "__builtin_offsetof", RID_OFFSETOF, 0 },
   { "__builtin_va_arg",        RID_VA_ARG,     0 },
   { "__complex",       RID_COMPLEX,    0 },
   { "__complex__",     RID_COMPLEX,    0 },
@@ -373,17 +346,14 @@ static const struct resword reswords[] =
 };
 
 void
-init_reswords ()
+init_reswords (void)
 {
   unsigned int i;
   tree id;
   int mask = ((flag_no_asm ? D_ASM : 0)
              | (flag_no_gnu_keywords ? D_EXT : 0));
 
-  /* It is not necessary to register ridpointers as a GC root, because
-     all the trees it points to are permanently interned in the
-     get_identifier hash anyway.  */
-  ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
+  ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
   for (i = 0; i < ARRAY_SIZE (reswords); i++)
     {
       id = get_identifier (reswords[i].word);
@@ -395,7 +365,7 @@ init_reswords ()
 }
 
 static void
-init_cp_pragma ()
+init_cp_pragma (void)
 {
   c_register_pragma (0, "vtable", handle_pragma_vtable);
   c_register_pragma (0, "unit", handle_pragma_unit);
@@ -405,16 +375,25 @@ init_cp_pragma ()
   c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
   c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
 }
-
+\f
 /* Initialize the C++ front end.  This function is very sensitive to
    the exact order that things are done here.  It would be nice if the
    initialization done by this routine were moved to its subroutines,
    and the ordering dependencies clarified and reduced.  */
-const char *
-cxx_init (filename)
-     const char *filename;
+bool
+cxx_init (void)
 {
-  input_filename = "<internal>";
+  static const enum tree_code stmt_codes[] = {
+    c_common_stmt_codes,
+    cp_stmt_codes
+  };
+
+  INIT_STATEMENT_CODES (stmt_codes);
+
+  /* We cannot just assign to input_filename because it has already
+     been initialized and will be used later as an N_BINCL for stabs+
+     debugging.  */
+  push_srcloc ("<internal>", 0);
 
   init_reswords ();
   init_tree ();
@@ -425,21 +404,7 @@ cxx_init (filename)
 
   current_function_decl = NULL;
 
-  class_type_node = build_int_2 (class_type, 0);
-  TREE_TYPE (class_type_node) = class_type_node;
-  ridpointers[(int) RID_CLASS] = class_type_node;
-
-  record_type_node = build_int_2 (record_type, 0);
-  TREE_TYPE (record_type_node) = record_type_node;
-  ridpointers[(int) RID_STRUCT] = record_type_node;
-
-  union_type_node = build_int_2 (union_type, 0);
-  TREE_TYPE (union_type_node) = union_type_node;
-  ridpointers[(int) RID_UNION] = union_type_node;
-
-  enum_type_node = build_int_2 (enum_type, 0);
-  TREE_TYPE (enum_type_node) = enum_type_node;
-  ridpointers[(int) RID_ENUM] = enum_type_node;
+  class_type_node = ridpointers[(int) RID_CLASS];
 
   cxx_init_decl_processing ();
 
@@ -450,35 +415,29 @@ cxx_init (filename)
 
   interface_unknown = 1;
 
-  filename = c_common_init (filename);
-  if (filename == NULL)
-    return NULL;
+  if (c_common_init () == false)
+    {
+      pop_srcloc();
+      return false;
+    }
 
   init_cp_pragma ();
 
-  init_repo (filename);
+  init_repo (main_input_filename);
 
-  return filename;
+  pop_srcloc();
+  return true;
 }
 \f
 /* Helper function to load global variables with interface
    information.  */
 
 void
-extract_interface_info ()
+extract_interface_info (void)
 {
-  struct c_fileinfo *finfo = 0;
-
-  if (flag_alt_external_templates)
-    {
-      tree til = tinst_for_decl ();
-
-      if (til)
-       finfo = get_fileinfo (TINST_FILE (til));
-    }
-  if (!finfo)
-    finfo = get_fileinfo (input_filename);
+  struct c_fileinfo *finfo;
 
+  finfo = get_fileinfo (input_filename);
   interface_only = finfo->interface_only;
   interface_unknown = finfo->interface_unknown;
 }
@@ -487,8 +446,7 @@ extract_interface_info ()
    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
 
 static int
-interface_strcmp (s)
-     const char *s;
+interface_strcmp (const char* s)
 {
   /* Set the interface/implementation bits for this scope.  */
   struct impl_files *ifiles;
@@ -524,38 +482,12 @@ interface_strcmp (s)
   return 1;
 }
 
-void
-note_got_semicolon (type)
-     tree type;
-{
-  if (!TYPE_P (type))
-    abort ();
-  if (CLASS_TYPE_P (type))
-    CLASSTYPE_GOT_SEMICOLON (type) = 1;
-}
-
-void
-note_list_got_semicolon (declspecs)
-     tree declspecs;
-{
-  tree link;
-
-  for (link = declspecs; link; link = TREE_CHAIN (link))
-    {
-      tree type = TREE_VALUE (link);
-      if (type && TYPE_P (type))
-       note_got_semicolon (type);
-    }
-  clear_anon_tags ();
-}
 \f
 
 /* Parse a #pragma whose sole argument is a string constant.
    If OPT is true, the argument is optional.  */
 static tree
-parse_strconst_pragma (name, opt)
-     const char *name;
-     int opt;
+parse_strconst_pragma (const char* name, int opt)
 {
   tree result, x;
   enum cpp_ttype t;
@@ -577,24 +509,21 @@ parse_strconst_pragma (name, opt)
 }
 
 static void
-handle_pragma_vtable (dfile)
-     cpp_reader *dfile ATTRIBUTE_UNUSED;
+handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   parse_strconst_pragma ("vtable", 0);
   sorry ("#pragma vtable no longer supported");
 }
 
 static void
-handle_pragma_unit (dfile)
-     cpp_reader *dfile ATTRIBUTE_UNUSED;
+handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   /* Validate syntax, but don't do anything.  */
   parse_strconst_pragma ("unit", 0);
 }
 
 static void
-handle_pragma_interface (dfile)
-     cpp_reader *dfile ATTRIBUTE_UNUSED;
+handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   tree fname = parse_strconst_pragma ("interface", 1);
   struct c_fileinfo *finfo;
@@ -636,8 +565,7 @@ handle_pragma_interface (dfile)
    a matching #p interface for this to have any effect.  */
 
 static void
-handle_pragma_implementation (dfile)
-     cpp_reader *dfile ATTRIBUTE_UNUSED;
+handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   tree fname = parse_strconst_pragma ("implementation", 1);
   const char *main_filename;
@@ -669,7 +597,7 @@ handle_pragma_implementation (dfile)
     }
   if (ifiles == 0)
     {
-      ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
+      ifiles = xmalloc (sizeof (struct impl_files));
       ifiles->filename = main_filename;
       ifiles->next = impl_file_chain;
       impl_file_chain = ifiles;
@@ -678,8 +606,7 @@ handle_pragma_implementation (dfile)
 
 /* Indicate that this file uses Java-personality exception handling.  */
 static void
-handle_pragma_java_exceptions (dfile)
-     cpp_reader *dfile ATTRIBUTE_UNUSED;
+handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   tree x;
   if (c_lex (&x) != CPP_EOF)
@@ -688,31 +615,10 @@ handle_pragma_java_exceptions (dfile)
   choose_personality_routine (lang_java);
 }
 
-/* Return true if d is in a global scope.  */
-
-static int
-is_global (d)
-  tree d;
-{
-  while (1)
-    switch (TREE_CODE (d))
-      {
-      case ERROR_MARK:
-       return 1;
-
-      case OVERLOAD: d = OVL_FUNCTION (d); continue;
-      case TREE_LIST: d = TREE_VALUE (d); continue;
-      default:
-        my_friendly_assert (DECL_P (d), 980629);
-
-       return DECL_NAMESPACE_SCOPE_P (d);
-      }
-}
-
 /* Issue an error message indicating that the lookup of NAME (an
-   IDENTIFIER_NODE) failed.  */
+   IDENTIFIER_NODE) failed.  Returns the ERROR_MARK_NODE.  */
 
-void
+tree
 unqualified_name_lookup_error (tree name)
 {
   if (IDENTIFIER_OPNAME_P (name))
@@ -720,223 +626,65 @@ unqualified_name_lookup_error (tree name)
       if (name != ansi_opname (ERROR_MARK))
        error ("`%D' not defined", name);
     }
-  else if (current_function_decl == 0)
-    error ("`%D' was not declared in this scope", name);
   else
     {
-      if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
-         || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
-       {
-         static int undeclared_variable_notice;
-
-         error ("`%D' undeclared (first use this function)", name);
-
-         if (! undeclared_variable_notice)
-           {
-             error ("(Each undeclared identifier is reported only once for each function it appears in.)");
-             undeclared_variable_notice = 1;
-           }
-       }
-      /* Prevent repeated error messages.  */
-      SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
-      SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
-    }
-}
-
-tree
-do_identifier (token, args)
-     register tree token;
-     tree args;
-{
-  register tree id;
-
-  id = lookup_name (token, 0);
-
-  /* Do Koenig lookup if appropriate (inside templates we build lookup
-     expressions instead).
-
-     [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
-     finds the declaration of a class member function, the associated
-     namespaces and classes are not considered.  */
-
-  if (args && !current_template_parms && (!id || is_global (id)))
-    id = lookup_arg_dependent (token, id, args);
-
-  if (id == error_mark_node)
-    {
-      /* lookup_name quietly returns error_mark_node if we're parsing,
-        as we don't want to complain about an identifier that ends up
-        being used as a declarator.  So we call it again to get the error
-        message.  */
-      id = lookup_name (token, 0);
-      return error_mark_node;
-    }
-
-  if (!id || (TREE_CODE (id) == FUNCTION_DECL
-             && DECL_ANTICIPATED (id)))
-    {
-      if (current_template_parms)
-       return build_min_nt (LOOKUP_EXPR, token);
-      else if (IDENTIFIER_TYPENAME_P (token))
-       /* A templated conversion operator might exist.  */
-       return token;
-      else
+      error ("`%D' was not declared in this scope", name);
+      /* Prevent repeated error messages by creating a VAR_DECL with
+        this NAME in the innermost block scope.  */
+      if (current_function_decl)
        {
-         unqualified_name_lookup_error (token);
-         return error_mark_node;
+         tree decl;
+         decl = build_decl (VAR_DECL, name, error_mark_node);
+         DECL_CONTEXT (decl) = current_function_decl;
+         push_local_binding (name, decl, 0);
        }
     }
 
-  id = check_for_out_of_scope_variable (id);
-
-  /* TREE_USED is set in `hack_identifier'.  */
-  if (TREE_CODE (id) == CONST_DECL)
-    {
-      /* Check access.  */
-      if (IDENTIFIER_CLASS_VALUE (token) == id)
-       enforce_access (CP_DECL_CONTEXT(id), id);
-      if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
-       id = DECL_INITIAL (id);
-    }
-  else
-    id = hack_identifier (id, token);
-
-  /* We must look up dependent names when the template is
-     instantiated, not while parsing it.  For now, we don't
-     distinguish between dependent and independent names.  So, for
-     example, we look up all overloaded functions at
-     instantiation-time, even though in some cases we should just use
-     the DECL we have here.  We also use LOOKUP_EXPRs to find things
-     like local variables, rather than creating TEMPLATE_DECLs for the
-     local variables and then finding matching instantiations.  */
-  if (current_template_parms
-      && (is_overloaded_fn (id)
-         || (TREE_CODE (id) == VAR_DECL
-             && CP_DECL_CONTEXT (id)
-             && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
-         || TREE_CODE (id) == PARM_DECL
-         || TREE_CODE (id) == RESULT_DECL
-         || TREE_CODE (id) == USING_DECL))
-    id = build_min_nt (LOOKUP_EXPR, token);
-
-  return id;
+  return error_mark_node;
 }
 
+/* Like unqualified_name_lookup_error, but NAME is an unqualified-id
+   used as a function.  Returns an appropriate expression for
+   NAME.  */
+
 tree
-do_scoped_id (token, id)
-     tree token;
-     tree id;
+unqualified_fn_lookup_error (tree name)
 {
-  if (!id || (TREE_CODE (id) == FUNCTION_DECL
-             && DECL_ANTICIPATED (id)))
-    {
-      if (processing_template_decl)
-       {
-         id = build_min_nt (LOOKUP_EXPR, token);
-         LOOKUP_EXPR_GLOBAL (id) = 1;
-         return id;
-       }
-      if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
-        error ("`::%D' undeclared (first use here)", token);
-      id = error_mark_node;
-      /* Prevent repeated error messages.  */
-      SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
-    }
-  else
-    {
-      if (TREE_CODE (id) == ADDR_EXPR)
-       mark_used (TREE_OPERAND (id, 0));
-      else if (TREE_CODE (id) != OVERLOAD)
-       mark_used (id);
-    }
-  if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
-    {
-      /* XXX CHS - should we set TREE_USED of the constant? */
-      id = DECL_INITIAL (id);
-      /* This is to prevent an enum whose value is 0
-        from being considered a null pointer constant.  */
-      id = build1 (NOP_EXPR, TREE_TYPE (id), id);
-      TREE_CONSTANT (id) = 1;
-    }
-
   if (processing_template_decl)
     {
-      if (is_overloaded_fn (id))
+      /* In a template, it is invalid to write "f()" or "f(3)" if no
+        declaration of "f" is available.  Historically, G++ and most
+        other compilers accepted that usage since they deferred all name
+        lookup until instantiation time rather than doing unqualified
+        name lookup at template definition time; explain to the user what 
+        is going wrong.
+
+        Note that we have the exact wording of the following message in
+        the manual (trouble.texi, node "Name lookup"), so they need to
+        be kept in synch.  */
+      pedwarn ("there are no arguments to `%D' that depend on a template "
+              "parameter, so a declaration of `%D' must be available", 
+              name, name);
+      
+      if (!flag_permissive)
        {
-         id = build_min_nt (LOOKUP_EXPR, token);
-         LOOKUP_EXPR_GLOBAL (id) = 1;
-         return id;
+         static bool hint;
+         if (!hint)
+           {
+             error ("(if you use `-fpermissive', G++ will accept your code, "
+                    "but allowing the use of an undeclared name is "
+                    "deprecated)");
+             hint = true;
+           }
        }
-      /* else just use the decl */
-    }
-  return convert_from_reference (id);
-}
-
-tree
-identifier_typedecl_value (node)
-     tree node;
-{
-  tree t, type;
-  type = IDENTIFIER_TYPE_VALUE (node);
-  if (type == NULL_TREE)
-    return NULL_TREE;
-
-  if (IDENTIFIER_BINDING (node))
-    {
-      t = IDENTIFIER_VALUE (node);
-      if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
-       return t;
-    }
-  if (IDENTIFIER_NAMESPACE_VALUE (node))
-    {
-      t = IDENTIFIER_NAMESPACE_VALUE (node);
-      if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
-       return t;
+      return name;
     }
 
-  /* Will this one ever happen?  */
-  if (TYPE_MAIN_DECL (type))
-    return TYPE_MAIN_DECL (type);
-
-  /* We used to do an internal error of 62 here, but instead we will
-     handle the return of a null appropriately in the callers.  */
-  return NULL_TREE;
+  return unqualified_name_lookup_error (name);
 }
 
-#ifdef GATHER_STATISTICS
-/* The original for tree_node_kind is in the toplevel tree.c; changes there
-   need to be brought into here, unless this were actually put into a header
-   instead.  */
-/* Statistics-gathering stuff.  */
-typedef enum
-{
-  d_kind,
-  t_kind,
-  b_kind,
-  s_kind,
-  r_kind,
-  e_kind,
-  c_kind,
-  id_kind,
-  op_id_kind,
-  perm_list_kind,
-  temp_list_kind,
-  vec_kind,
-  x_kind,
-  lang_decl,
-  lang_type,
-  all_kinds
-} tree_node_kind;
-
-extern int tree_node_counts[];
-extern int tree_node_sizes[];
-#endif
-
 tree
-build_lang_decl (code, name, type)
-     enum tree_code code;
-     tree name;
-     tree type;
+build_lang_decl (enum tree_code code, tree name, tree type)
 {
   tree t;
 
@@ -950,8 +698,7 @@ build_lang_decl (code, name, type)
    and pushdecl (for functions generated by the backend).  */
 
 void
-retrofit_lang_decl (t)
-     tree t;
+retrofit_lang_decl (tree t)
 {
   struct lang_decl *ld;
   size_t size;
@@ -961,7 +708,7 @@ retrofit_lang_decl (t)
   else
     size = sizeof (struct lang_decl_flags);
 
-  ld = (struct lang_decl *) ggc_alloc_cleared (size);
+  ld = ggc_alloc_cleared (size);
 
   ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
   ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
@@ -970,7 +717,8 @@ retrofit_lang_decl (t)
     ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
 
   DECL_LANG_SPECIFIC (t) = ld;
-  if (current_lang_name == lang_name_cplusplus)
+  if (current_lang_name == lang_name_cplusplus
+      || decl_linkage (t) == lk_none)
     SET_DECL_LANGUAGE (t, lang_cplusplus);
   else if (current_lang_name == lang_name_c)
     SET_DECL_LANGUAGE (t, lang_c);
@@ -985,8 +733,7 @@ retrofit_lang_decl (t)
 }
 
 void
-cxx_dup_lang_specific_decl (node)
-     tree node;
+cxx_dup_lang_specific_decl (tree node)
 {
   int size;
   struct lang_decl *ld;
@@ -998,7 +745,7 @@ cxx_dup_lang_specific_decl (node)
     size = sizeof (struct lang_decl_flags);
   else
     size = sizeof (struct lang_decl);
-  ld = (struct lang_decl *) ggc_alloc (size);
+  ld = ggc_alloc (size);
   memcpy (ld, DECL_LANG_SPECIFIC (node), size);
   DECL_LANG_SPECIFIC (node) = ld;
 
@@ -1011,8 +758,7 @@ cxx_dup_lang_specific_decl (node)
 /* Copy DECL, including any language-specific parts.  */
 
 tree
-copy_decl (decl)
-     tree decl;
+copy_decl (tree decl)
 {
   tree copy;
 
@@ -1024,8 +770,7 @@ copy_decl (decl)
 /* Replace the shared language-specific parts of NODE with a new copy.  */
 
 static void
-copy_lang_type (node)
-     tree node;
+copy_lang_type (tree node)
 {
   int size;
   struct lang_type *lt;
@@ -1037,7 +782,7 @@ copy_lang_type (node)
     size = sizeof (struct lang_type);
   else
     size = sizeof (struct lang_type_ptrmem);
-  lt = (struct lang_type *) ggc_alloc (size);
+  lt = ggc_alloc (size);
   memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
   TYPE_LANG_SPECIFIC (node) = lt;
 
@@ -1050,8 +795,7 @@ copy_lang_type (node)
 /* Copy TYPE, including any language-specific parts.  */
 
 tree
-copy_type (type)
-     tree type;
+copy_type (tree type)
 {
   tree copy;
 
@@ -1061,10 +805,9 @@ copy_type (type)
 }
 
 tree
-cxx_make_type (code)
-     enum tree_code code;
+cxx_make_type (enum tree_code code)
 {
-  register tree t = make_node (code);
+  tree t = make_node (code);
 
   /* Create lang_type structure.  */
   if (IS_AGGR_TYPE_CODE (code)
@@ -1072,8 +815,7 @@ cxx_make_type (code)
     {
       struct lang_type *pi;
 
-      pi = ((struct lang_type *)
-           ggc_alloc_cleared (sizeof (struct lang_type)));
+      pi = ggc_alloc_cleared (sizeof (struct lang_type));
 
       TYPE_LANG_SPECIFIC (t) = pi;
       pi->u.c.h.is_lang_type_class = 1;
@@ -1114,8 +856,7 @@ cxx_make_type (code)
 }
 
 tree
-make_aggr_type (code)
-     enum tree_code code;
+make_aggr_type (enum tree_code code)
 {
   tree t = cxx_make_type (code);
 
@@ -1129,8 +870,7 @@ make_aggr_type (code)
    RID.  */
 
 int
-cp_type_qual_from_rid (rid)
-     tree rid;
+cp_type_qual_from_rid (tree rid)
 {
   if (rid == ridpointers[(int) RID_CONST])
     return TYPE_QUAL_CONST;