]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/10158 (ICE with templates and friends)
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 27 Mar 2003 12:19:13 +0000 (12:19 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 27 Mar 2003 12:19:13 +0000 (12:19 +0000)
cp:
PR c++/10158
* parser.c (cp_parser_function_definition): Set
DECL_INITIALIZED_IN_CLASS for members.
* pt.c (instantiate_decl): Only reduce the template args for
friends that are not defined in class.
testsuite:
PR c++/10158
* g++.dg/template/friend18.C: New test.

From-SVN: r64920

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/friend18.C [new file with mode: 0644]

index 1fe0268f17b7abffe9ab03cc01e51f642339224f..8d835ece2c90b05d104dbe3d2465f57010be6f3a 100644 (file)
@@ -1,3 +1,11 @@
+2003-03-27  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/10158
+       * parser.c (cp_parser_function_definition): Set
+       DECL_INITIALIZED_IN_CLASS for members.
+       * pt.c (instantiate_decl): Only reduce the template args for
+       friends that are not defined in class.
+
 2003-03-25  Jason Merrill  <jason@redhat.com>
 
        * call.c (print_z_candidate): Change name of first arg to msgid.
 2003-03-24  Nathan Sidwell  <nathan@codesourcery.com>
        
        PR c++/9898, PR c++/383, DR 322
-       * pt.c (maybe_adjust_types_for_deduction) [DEDUCE_CONV]: Look
+       * pt.c (maybe_adjust_types_for_deduction) <DEDUCE_CONV>: Look
        through reference types on both PARM and ARG.
 
 2003-03-24  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/10119
-       * error.c (dump_expr) [BASELINK]: Use dump_expr.
+       * error.c (dump_expr) <BASELINK>: Use dump_expr.
        * pt.c (maybe_fold_nontype_args): New function.
-       (tsubst_copy) [SCOPE_REF]: Subst any template_id args.
-       [TEMPLATE_ID_EXPR]: Break out folding code, call it.
-       (tsubst_copy_and_build) [TEMPLATE_ID_EXPR]: Call
+       (tsubst_copy) <SCOPE_REF>: Subst any template_id args.
+       <TEMPLATE_ID_EXPR>: Break out folding code, call it.
+       (tsubst_copy_and_build) <TEMPLATE_ID_EXPR>: Call
        maybe_fold_nontype_args.
 
 2003-03-24  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/10026
-       * decl2.c (arg_assoc_type) [ERROR_MARK]: Don't die.
+       * decl2.c (arg_assoc_type) <ERROR_MARK>: Don't die.
 
 2003-03-23  Mark Mitchell  <mark@codesourcery.com>
 
index 1c871e8fcdcbb5f793ba01e991c8967c7fbf5b62..82fc020e6308f8e80b0b79de77b836dc19748138 100644 (file)
@@ -1987,7 +1987,8 @@ struct lang_decl GTY(())
    (TREE_LANG_FLAG_1 (VAR_DECL_CHECK (NODE)))
 
 /* Nonzero if the DECL was initialized in the class definition itself,
-   rather than outside the class.  */
+   rather than outside the class.  This is used for both static member
+   VAR_DECLS, and FUNTION_DECLS that are defined in the class. */
 #define DECL_INITIALIZED_IN_CLASS_P(DECL) \
  (DECL_LANG_SPECIFIC (DECL)->decl_flags.initialized_in_class)
 
index 9c157c29a0a96a5d12e04696b203988c84392cdc..8cc46f98325b128860fe066f661417f887450bbc 100644 (file)
@@ -11046,6 +11046,10 @@ cp_parser_function_definition (cp_parser* parser, bool* friend_p)
       DECL_PENDING_INLINE_INFO (fn) = cache;
       DECL_PENDING_INLINE_P (fn) = 1;
 
+      /* We need to know that this was defined in the class, so that
+        friend templates are handled correctly.  */
+      DECL_INITIALIZED_IN_CLASS_P (fn) = 1;
+
       /* We're done with the inline definition.  */
       finish_method (fn);
 
index ab529701b5fd87b9c434f8023574e4034894c2ce..c04c602d8675fe90b5c08ea96fc45394b981b0bd 100644 (file)
@@ -10804,12 +10804,14 @@ instantiate_decl (d, defer_ok)
   td = template_for_substitution (d);
   code_pattern = DECL_TEMPLATE_RESULT (td);
 
-  /* In the case of a friend template whose definition is provided
-     outside the class, we may have too many arguments.  Drop the ones
-     we don't need.  */
-  args = get_innermost_template_args (gen_args,
-                                     TMPL_PARMS_DEPTH 
-                                     (DECL_TEMPLATE_PARMS (td)));
+  if (DECL_NAMESPACE_SCOPE_P (d) && !DECL_INITIALIZED_IN_CLASS_P (d))
+    /* In the case of a friend template whose definition is provided
+       outside the class, we may have too many arguments.  Drop the
+       ones we don't need.  */
+    args = get_innermost_template_args
+      (gen_args, TMPL_PARMS_DEPTH  (DECL_TEMPLATE_PARMS (td)));
+  else
+    args = gen_args;
 
   if (TREE_CODE (d) == FUNCTION_DECL)
     pattern_defined = (DECL_SAVED_TREE (code_pattern) != NULL_TREE);
index 1c9a119ed0c6d75793a16ee0bcef668a06548361..cb6431052c17a0119ff18a66efec381c36c6a45d 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-27  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/10158
+       * g++.dg/template/friend18.C: New test.
+
 2003-03-26  Roger Sayle  <roger@eyesopen.com>
 
        * g77.f-torture/compile/20030326-1.f: New test case.
diff --git a/gcc/testsuite/g++.dg/template/friend18.C b/gcc/testsuite/g++.dg/template/friend18.C
new file mode 100644 (file)
index 0000000..04ba26e
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do run }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Mar 2003 <nathan@codesourcery.com>
+
+// PR 10158. implicit inline template friends ICE'd
+
+template <int N> struct X
+{
+  template <int M> friend int foo(X const &)
+  {
+    return N * 10000 + M;
+  }
+};
+X<1234> bring;
+
+int main() {
+  return foo<5678> (bring) != 12345678;
+}