decl.c (lookup_name_real): Also do implicit typename thing for artificial TYPE_DECLs.
authorJason Merrill <jason@yorick.cygnus.com>
Tue, 1 Sep 1998 11:51:41 +0000 (11:51 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 1 Sep 1998 11:51:41 +0000 (07:51 -0400)
* decl.c (lookup_name_real): Also do implicit typename thing for
artificial TYPE_DECLs.
* search.c (lookup_field): Likewise.
(lookup_fnfields, lookup_field): Adjust for implicit typename kludge.
* semantics.c (begin_constructor_declarator): Use enter_scope_of.
(enter_scope_of): Extract type from implicit typename.
(begin_class_definition): Likewise.
* lex.c (identifier_type): Handle implicit typename when checking
for SELFNAME.
* cp-tree.h: Declare flag_strict_prototype.
* lex.c (do_scoped_id, do_identifier): Don't implicitly_declare if
-fstrict-prototype.
* decl.c (init_decl_processing): If -f{no,-}strict-prototype wasn't
specified, set it to the value of pedantic.

From-SVN: r22158

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/except.c
gcc/cp/lang-options.h
gcc/cp/lex.c
gcc/cp/pt.c
gcc/cp/search.c
gcc/cp/semantics.c

index 37c16b3f6cf6d485334689c9ba476088e26e1521..665f35d01559b0ff9cf0c75409da1f730441a498 100644 (file)
@@ -1,3 +1,21 @@
+1998-09-01  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * decl.c (lookup_name_real): Also do implicit typename thing for
+       artificial TYPE_DECLs.
+       * search.c (lookup_field): Likewise.
+       (lookup_fnfields, lookup_field): Adjust for implicit typename kludge.
+       * semantics.c (begin_constructor_declarator): Use enter_scope_of.
+       (enter_scope_of): Extract type from implicit typename.
+       (begin_class_definition): Likewise.
+       * lex.c (identifier_type): Handle implicit typename when checking
+       for SELFNAME.
+
+       * cp-tree.h: Declare flag_strict_prototype.
+       * lex.c (do_scoped_id, do_identifier): Don't implicitly_declare if
+       -fstrict-prototype.
+       * decl.c (init_decl_processing): If -f{no,-}strict-prototype wasn't
+       specified, set it to the value of pedantic.
+
 1998-09-01  Mark Mitchell  <mark@markmitchell.com>
 
        * decl2.c (arg_assoc): Handle template-id expressions as arguments.
index e4b07be0ad996660df74975a029a8c30a09b17f3..096617a5aa4c2b44b43054dac29acae9b478beaa 100644 (file)
@@ -477,6 +477,11 @@ extern int flag_do_squangling;
    required.  */
 extern int flag_optional_diags;
 
+/* Nonzero means do not consider empty argument prototype to mean function
+   takes no arguments.  */
+
+extern int flag_strict_prototype;
+
 /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc.  */
 extern int flag_vtable_gc;
 \f
index fe9160dc2c031743af75733754f9fadb5641a688..2abcd1ac1807f233349d572721868f198a53dc9f 100644 (file)
@@ -5091,8 +5091,7 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only)
       else if (processing_template_decl
               && classval && TREE_CODE (classval) == TYPE_DECL
               && ! currently_open_class (DECL_CONTEXT (classval))
-              && uses_template_parms (current_class_type)
-              && ! DECL_ARTIFICIAL (classval))
+              && uses_template_parms (current_class_type))
        classval = lookup_field (current_class_type, name, 0, 1);
 
       /* yylex() calls this with -2, since we should never start digging for
@@ -5470,7 +5469,6 @@ init_decl_processing ()
   int wchar_type_size;
   tree temp;
   tree array_domain_type;
-  extern int flag_strict_prototype;
   tree vb_off_identifier = NULL_TREE;
   /* Function type `char *(char *, char *)' and similar ones */
   tree string_ftype_ptr_ptr, int_ftype_string_string;
@@ -5492,12 +5490,9 @@ init_decl_processing ()
   current_lang_name = NULL_TREE;
 
   if (flag_strict_prototype == 2)
-    {
-      if (pedantic)
-       strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
-    }
-  else
-    strict_prototypes_lang_c = flag_strict_prototype;
+    flag_strict_prototype = pedantic;
+
+  strict_prototypes_lang_c = flag_strict_prototype;
 
   /* Initially, C.  */
   current_lang_name = lang_name_c;
index b441c6b628d09ac395bd6f29ca7076dc4cb0c8ce..69315beba39d3995198a8e438b1693708a700f14 100644 (file)
@@ -826,7 +826,6 @@ process_start_catch_block (declspecs, declarator)
 }
 
 
-
 /* Call this to end a catch block.  Its responsible for emitting the
    code to handle jumping back to the correct place, and for emitting
    the label to jump to if this catch block didn't match.  */
index 97ec99b38e78b88a7b365d8ba95e1640ae3eebaa..e6ad6595b100761e97c22f435a635a366eaf9bc3 100644 (file)
@@ -1,5 +1,5 @@
 /* Definitions for switches for C++.
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
index 859a6bea2afb72042bf0d11340048a6286c39858..b789b28438b3e2a6af030992effceb3557e3d2b6 100644 (file)
@@ -2754,6 +2754,7 @@ int
 identifier_type (decl)
      tree decl;
 {
+  tree t;
   if (TREE_CODE (decl) == TEMPLATE_DECL)
     {
       if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
@@ -2763,7 +2764,6 @@ identifier_type (decl)
     }
   if (looking_for_template && really_overloaded_fn (decl))
     {
-      tree t;
       for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
        if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t))) 
          return PFUNCNAME;
@@ -2772,10 +2772,20 @@ identifier_type (decl)
     return NSNAME;
   if (TREE_CODE (decl) != TYPE_DECL)
     return IDENTIFIER;
-  if (((got_scope && TREE_TYPE (decl) == got_scope)
-       || TREE_TYPE (decl) == current_class_type)
-      && DECL_ARTIFICIAL (decl))
+  if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
+    return SELFNAME;
+
+  /* A constructor declarator for a template type will get here as an
+     implicit typename, a TYPENAME_TYPE with a type.  */
+  t = got_scope;
+  if (t && TREE_CODE (t) == TYPENAME_TYPE)
+    t = TREE_TYPE (t);
+  decl = TREE_TYPE (decl);
+  if (TREE_CODE (decl) == TYPENAME_TYPE)
+    decl = TREE_TYPE (decl);
+  if (t && t == decl)
     return SELFNAME;
+
   return TYPENAME;
 }
 
@@ -2902,7 +2912,7 @@ do_identifier (token, parsing, args)
            cp_error ("`%D' not defined", token);
          id = error_mark_node;
        }
-      else if (in_call)
+      else if (in_call && ! flag_strict_prototype)
        {
          id = implicitly_declare (token);
        }
@@ -3054,7 +3064,8 @@ do_scoped_id (token, parsing)
          LOOKUP_EXPR_GLOBAL (id) = 1;
          return id;
        }
-      if (parsing && (yychar == '(' || yychar == LEFT_RIGHT))
+      if (parsing && (yychar == '(' || yychar == LEFT_RIGHT)
+         && ! flag_strict_prototype)
        id = implicitly_declare (token);
       else
        {
index fff3fbc048db5f92b2a38faa4b46a5f2800c66ae..aadd36d6c715f960bd492d333343689b3c55d547 100644 (file)
@@ -2598,7 +2598,6 @@ coerce_template_template_parms (parm_parms, arg_parms, in_decl, outer_args)
   return 1;
 }
 
-
 /* Convert the indicated template ARG as necessary to match the
    indicated template PARM.  Returns the converted ARG, or
    error_mark_node if the conversion was unsuccessful.  Error messages
index fa3109daac6c6d57e54f504b2cbaaf10a5775207..1c3a187abeb245ba922927f3750aef5d980dfd3a 100644 (file)
@@ -1030,9 +1030,12 @@ lookup_field (xbasetype, name, protect, want_type)
       basetype_chain = TREE_CHAIN (basetype_chain);
       basetype_path = TREE_VALUE (basetype_chain);
       if (TREE_CHAIN (basetype_chain))
-       my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path)
-                           == TREE_VALUE (TREE_CHAIN (basetype_chain)),
-                           980827);
+       my_friendly_assert
+         ((BINFO_INHERITANCE_CHAIN (basetype_path)
+           == TREE_VALUE (TREE_CHAIN (basetype_chain)))
+          /* We only approximate base info for partial instantiations.  */ 
+          || current_template_parms,
+          980827);
       else
        my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path)
                            == NULL_TREE, 980827);
@@ -1187,7 +1190,6 @@ lookup_field (xbasetype, name, protect, want_type)
 
   /* Do implicit typename stuff.  */
   if (rval && TREE_CODE (rval) == TYPE_DECL
-      && ! DECL_ARTIFICIAL (rval)
       && processing_template_decl
       && ! currently_open_class (BINFO_TYPE (rval_binfo))
       && uses_template_parms (type))
@@ -1480,9 +1482,12 @@ lookup_fnfields (basetype_path, name, complain)
       basetype_chain = TREE_CHAIN (basetype_chain);
       basetype_path = TREE_VALUE (basetype_chain);
       if (TREE_CHAIN (basetype_chain))
-       my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path)
-                           == TREE_VALUE (TREE_CHAIN (basetype_chain)),
-                           980827);
+       my_friendly_assert
+         ((BINFO_INHERITANCE_CHAIN (basetype_path)
+           == TREE_VALUE (TREE_CHAIN (basetype_chain)))
+          /* We only approximate base info for partial instantiations.  */ 
+          || current_template_parms,
+          980827);
       else
        my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path)
                            == NULL_TREE, 980827);
index 6bb3cd05123d148b7d7393e3514ba1551845042f..10ffe1987bfa573349aa8b4c1b51cb3eea345af3 100644 (file)
@@ -1114,13 +1114,7 @@ begin_constructor_declarator (scope, name)
      tree name;
 {
   tree result = build_parse_node (SCOPE_REF, scope, name);
-
-  if (scope != current_class_type)
-    {
-      push_nested_class (scope, 3);
-      TREE_COMPLEXITY (result) = current_class_depth;
-    }
-
+  enter_scope_of (result);
   return result;
 }
 
@@ -1214,24 +1208,27 @@ tree
 begin_class_definition (t)
      tree t;
 {
-  tree new_type = t;
-
   push_obstacks_nochange ();
   end_temporary_allocation ();
   
   if (t == error_mark_node
       || ! IS_AGGR_TYPE (t))
     {
-      t = new_type = make_lang_type (RECORD_TYPE);
+      t = make_lang_type (RECORD_TYPE);
       pushtag (make_anon_name (), t, 0);
     }
+
+  /* In a definition of a member class template, we will get here with an
+     implicit typename, a TYPENAME_TYPE with a type.  */
+  if (TREE_CODE (t) == TYPENAME_TYPE)
+    t = TREE_TYPE (t);
+
   if (TYPE_SIZE (t))
     duplicate_tag_error (t);
   if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
     {
       t = make_lang_type (TREE_CODE (t));
       pushtag (TYPE_IDENTIFIER (t), t, 0);
-      new_type = t;
     }
   if (processing_template_decl && TYPE_CONTEXT (t)
       && TREE_CODE (TYPE_CONTEXT (t)) != NAMESPACE_DECL
@@ -1267,9 +1264,9 @@ begin_class_definition (t)
       CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
     }
 #if 0
-  t = TYPE_IDENTIFIER ($<ttype>0);
-  if (t && IDENTIFIER_TEMPLATE (t))
-    overload_template_name (t, 1);
+  tmp = TYPE_IDENTIFIER ($<ttype>0);
+  if (tmp && IDENTIFIER_TEMPLATE (tmp))
+    overload_template_name (tmp, 1);
 #endif
   reset_specialization();
   
@@ -1278,7 +1275,7 @@ begin_class_definition (t)
      that we can get it back later.  */
   begin_tree ();
 
-  return new_type;
+  return t;
 }
 
 /* Finish a class definition T, with the indicated COMPONENTS, and
@@ -1432,6 +1429,13 @@ enter_scope_of (sr)
     }
   else if (scope != current_class_type)
     {
+      if (TREE_CODE (scope) == TYPENAME_TYPE)
+       {
+         /* In a declarator for a template class member, the scope will
+            get here as an implicit typename, a TYPENAME_TYPE with a type.  */
+         scope = TREE_TYPE (scope);
+         TREE_OPERAND (sr, 0) = scope;
+       }
       push_nested_class (scope, 3);
       TREE_COMPLEXITY (sr) = current_class_depth;
     }