tree.c (is_overloaded_fn): Handle getting a fn template.
authorJason Merrill <jason@gcc.gnu.org>
Wed, 3 Dec 1997 19:46:56 +0000 (14:46 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 3 Dec 1997 19:46:56 +0000 (14:46 -0500)
* tree.c (is_overloaded_fn): Handle getting a fn template.
(really_overloaded_fn): Likewise.
* error.c (dump_decl): Handle TEMPLATE_ID_EXPRs better.
* pt.c (check_explicit_specialization): Tweak.
(determine_explicit_specialization): Tweak.

* tree.c, cp-tree.h (get_target_expr): New fn.

1997-12-02  Mark Mitchell  <mmitchell@usa.net>

* pt.c (determine_explicit_specialization): Avoid an internal
error for bad specializations.

* method.c (build_overload_value): Handle SCOPE_REF.

From-SVN: r16928

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/error.c
gcc/cp/method.c
gcc/cp/pt.c
gcc/cp/tree.c

index a91d9e30deb834e76da1677fb277f2cf23e7b5e5..7def192d6fad2ee208bb4794f4fb836e9d58f95b 100644 (file)
@@ -1,3 +1,20 @@
+Wed Dec  3 11:44:52 1997  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * tree.c (is_overloaded_fn): Handle getting a fn template.
+       (really_overloaded_fn): Likewise.
+       * error.c (dump_decl): Handle TEMPLATE_ID_EXPRs better.
+       * pt.c (check_explicit_specialization): Tweak.
+       (determine_explicit_specialization): Tweak.
+
+       * tree.c, cp-tree.h (get_target_expr): New fn.
+
+1997-12-02  Mark Mitchell  <mmitchell@usa.net>
+
+       * pt.c (determine_explicit_specialization): Avoid an internal
+       error for bad specializations.
+
+       * method.c (build_overload_value): Handle SCOPE_REF.
+
 Tue Dec  2 19:18:50 1997  Mike Stump  <mrs@wrs.com>
 
        * class.c (prepare_fresh_vtable): Enable even more complex MI
index 9b69b7bc5dca4f9ee192aa3746ad537f1167f7a5..e1653020194cccea7170650eb318b4a5ac3365c9 100644 (file)
@@ -2425,6 +2425,7 @@ extern tree min_tree_cons                 PROTO((tree, tree, tree));
 extern int lvalue_p                            PROTO((tree));
 extern int lvalue_or_else                      PROTO((tree, char *));
 extern tree build_cplus_new                    PROTO((tree, tree));
+extern tree get_target_expr                    PROTO((tree));
 extern tree break_out_cleanups                 PROTO((tree));
 extern tree break_out_calls                    PROTO((tree));
 extern tree build_cplus_method_type            PROTO((tree, tree, tree));
index ccc5b46113ec595ac4f42b37c3e7d978d53adb5a..206474130cd4efd7506860e30942ac330b5ec6ac 100644 (file)
@@ -779,7 +779,10 @@ dump_decl (t, v)
     case TEMPLATE_ID_EXPR:
       {
        tree args;
-       dump_type (TREE_OPERAND (t, 0), v);
+       tree name = TREE_OPERAND (t, 0);
+       if (is_overloaded_fn (name))
+         name = DECL_NAME (get_first_fn (name));
+       dump_decl (name, v);
        OB_PUTC ('<');
        for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
          {
index c16f6eaf02f66dc10b26e7052266c1b491e745ac..0ab0e236dd5c093f9fbca8b68da28027f69a5fe6 100644 (file)
@@ -641,6 +641,14 @@ build_overload_value (type, value, in_template)
          build_overload_identifier (DECL_ASSEMBLER_NAME (value));
          return;
        }
+      else if (TREE_CODE (value) == SCOPE_REF)
+       {
+         OB_PUTC2 ('Q', '1');
+         numeric_output_need_bar = 0;
+         build_overload_name (TREE_OPERAND (value, 0), 0, 0);
+         build_overload_identifier (TREE_OPERAND (value, 1));
+         return;
+       }
       else
        my_friendly_abort (71);
       break; /* not really needed */
index 1e9c9053717af83b5c60edbeaddc588c3296bed5..58ecc3ce456d14a5ee98023c88695b1aadfffcab 100644 (file)
@@ -352,27 +352,27 @@ determine_explicit_specialization (template_id, type, targs_out,
   int overloaded;
   tree fns;
   tree matching_fns = NULL_TREE;
-  tree name = NULL_TREE;
   tree result;
   tree fn;
 
-  my_friendly_assert (TREE_CODE (template_id) == TEMPLATE_ID_EXPR,
-                     0); 
+  my_friendly_assert (TREE_CODE (template_id) == TEMPLATE_ID_EXPR
+                     && TREE_OPERAND (template_id, 0), 0); 
                      
   fns = TREE_OPERAND (template_id, 0);
 
-  overloaded = fns != NULL_TREE && really_overloaded_fn (fns);
+  if (is_overloaded_fn (fns))
+    fn = get_first_fn (fns);
+  else
+    fn = NULL_TREE;
+
+  overloaded = really_overloaded_fn (fns);
 
-  for (fn = (fns != NULL_TREE) ? get_first_fn (fns) : NULL_TREE; 
-       fn != NULL_TREE; 
+  for (; fn != NULL_TREE; 
        fn = overloaded ? DECL_CHAIN (fn) : NULL_TREE)
     {
       int dummy = 0;
       tree targs;
 
-      if (name == NULL_TREE)
-       name = DECL_NAME (fn);
-
       if (TREE_CODE (fn) != TEMPLATE_DECL
          || (need_member_template && !is_member_template (fn)))
        continue;
@@ -424,8 +424,9 @@ determine_explicit_specialization (template_id, type, targs_out,
   if (matching_fns == NULL_TREE)
     {
       if (complain)
-       cp_error ("Specialization of `%s' does not match any template declaration.",
-                 IDENTIFIER_POINTER (name));
+       cp_error ("`%D' does not match any template declaration.",
+                 template_id);
+
       *targs_out = NULL_TREE;
       return NULL_TREE;
     }
@@ -496,8 +497,8 @@ check_explicit_specialization (declarator, decl, template_count, flags)
          && !processing_explicit_specialization (template_count)
          && !is_friend)
        {
-         if (!have_def && ! template_header_count)
-           /* This is not an explicit specialization.  It must be
+         if (! have_def && ! template_header_count && ! ctype)
+           /* This is not an explict specialization.  It must be
               an explicit instantiation.  */
            return 2;
          else if (template_header_count > template_count
@@ -507,7 +508,7 @@ check_explicit_specialization (declarator, decl, template_count, flags)
                        declarator);
              return 0;
            }
-         else if (pedantic)
+         else if (pedantic || uses_template_parms (decl))
            pedwarn ("explicit specialization not preceeded by `template <>'");
        }
 
index 98b1a6d3b770e146a6eb742bccddaa6dcad9b4e7..2d048abff4278dc4d613707309617d2ba357c9e5 100644 (file)
@@ -248,6 +248,7 @@ build_cplus_new (type, init)
     return init;
 
   slot = build (VAR_DECL, type);
+  DECL_ARTIFICIAL (slot) = 1;
   layout_decl (slot, 0);
   rval = build (NEW_EXPR, type,
                TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
@@ -258,6 +259,25 @@ build_cplus_new (type, init)
   return rval;
 }
 
+/* Encapsulate the expression INIT in a TARGET_EXPR.  */
+
+tree
+get_target_expr (init)
+     tree init;
+{
+  tree slot;
+  tree rval;
+
+  slot = build (VAR_DECL, TREE_TYPE (init));
+  DECL_ARTIFICIAL (slot) = 1;
+  layout_decl (slot, 0);
+  rval = build (TARGET_EXPR, TREE_TYPE (init), slot, init,
+               NULL_TREE, NULL_TREE);
+  TREE_SIDE_EFFECTS (rval) = 1;
+
+  return rval;
+}
+
 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
    these CALL_EXPRs with tree nodes that will perform the cleanups.  */
 
@@ -1273,15 +1293,14 @@ int
 is_overloaded_fn (x)
      tree x;
 {
-  if (TREE_CODE (x) == FUNCTION_DECL)
-    return 1;
-
-  if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
+  if (TREE_CODE (x) == FUNCTION_DECL
+      || TREE_CODE (x) == TEMPLATE_ID_EXPR
+      || DECL_FUNCTION_TEMPLATE_P (x))
     return 1;
 
   if (TREE_CODE (x) == TREE_LIST
       && (TREE_CODE (TREE_VALUE (x)) == FUNCTION_DECL
-         || TREE_CODE (TREE_VALUE (x)) == TEMPLATE_DECL))
+         || DECL_FUNCTION_TEMPLATE_P (TREE_VALUE (x))))
     return 1;
 
   return 0;
@@ -1291,7 +1310,8 @@ int
 really_overloaded_fn (x)
      tree x;
 {     
-  if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
+  if (TREE_CODE (x) == TEMPLATE_ID_EXPR
+      || DECL_FUNCTION_TEMPLATE_P (x))
     return 1;
 
   if (TREE_CODE (x) == TREE_LIST