From: Nathan Sidwell Date: Thu, 27 Mar 2003 12:19:13 +0000 (+0000) Subject: re PR c++/10158 (ICE with templates and friends) X-Git-Tag: releases/gcc-3.4.0~7643 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=649fc72d2638dfc1edac57bb5dc9525bdf4911e5;p=thirdparty%2Fgcc.git re PR c++/10158 (ICE with templates and friends) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1fe0268f17b7..8d835ece2c90 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2003-03-27 Nathan Sidwell + + 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 * call.c (print_z_candidate): Change name of first arg to msgid. @@ -6,23 +14,23 @@ 2003-03-24 Nathan Sidwell 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) : Look through reference types on both PARM and ARG. 2003-03-24 Nathan Sidwell PR c++/10119 - * error.c (dump_expr) [BASELINK]: Use dump_expr. + * error.c (dump_expr) : 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) : Subst any template_id args. + : Break out folding code, call it. + (tsubst_copy_and_build) : Call maybe_fold_nontype_args. 2003-03-24 Nathan Sidwell PR c++/10026 - * decl2.c (arg_assoc_type) [ERROR_MARK]: Don't die. + * decl2.c (arg_assoc_type) : Don't die. 2003-03-23 Mark Mitchell diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1c871e8fcdcb..82fc020e6308 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9c157c29a0a9..8cc46f98325b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ab529701b5fd..c04c602d8675 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c9a119ed0c6..cb6431052c17 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-03-27 Nathan Sidwell + + PR c++/10158 + * g++.dg/template/friend18.C: New test. + 2003-03-26 Roger Sayle * 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 index 000000000000..04ba26e9830c --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend18.C @@ -0,0 +1,19 @@ +// { dg-do run } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Mar 2003 + +// PR 10158. implicit inline template friends ICE'd + +template struct X +{ + template friend int foo(X const &) + { + return N * 10000 + M; + } +}; +X<1234> bring; + +int main() { + return foo<5678> (bring) != 12345678; +}