diff options
author | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-29 14:30:41 +0000 |
---|---|---|
committer | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-29 14:30:41 +0000 |
commit | 94c17f03f6125d9c2357594be55f5e6fdd054a4b (patch) | |
tree | 2ee93041dfe1e8e764098880a0e8717715707c64 /gcc/cp/error.c | |
parent | 338cce8f9ae07a2135b04b693f882c03d2de3bb5 (diff) | |
download | gcc-94c17f03f6125d9c2357594be55f5e6fdd054a4b.tar.gz |
Fix PRs c++/42758, c++/42634, c++/42797
... and mitigate PR c++/42336
gcc/cp/ChangeLog:
PR c++/42758
PR c++/42634
PR c++/42336
PR c++/42797
PR c++/42880
* cp-tree.h (NON_DEFAULT_TEMPLATE_ARGS_COUNT,
SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT,
GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT): New accessor macros.
* pt.c (coerce_template_parms, type_unification_real,
expand_template_argument_pack, coerce_template_parameter_pack):
Set the non default template args count.
(current_template_args): Always set non defaulted
template args count when compiled with --enable-checking
(tsubst_template_args, type_unification_real): Propagate the non
defaulted template args count.
* error.c (get_non_default_template_args_count): Renamed
count_non_default_template_args into this. Don't calculate the
non default template argument count anymore. Use the new
accessor macros above to get it.
(dump_template_argument_list, dump_type, dump_decl,
dump_template_parms): Adjust.
* parser.c (cp_parser_template_argument_list): Always set defaulted
template args count when compiled with --enable-checking.
gcc/testsuite/ChangeLog:
PR c++/42758
PR c++/42634
PR c++/42336
PR c++/42797
PR c++/42880
* g++.dg/other/crash-5.C: New test.
* g++.dg/other/crash-6.C: New test.
* g++.dg/other/crash-7.C: New test.
* g++.dg/other/crash-8.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156351 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/error.c')
-rw-r--r-- | gcc/cp/error.c | 56 |
1 files changed, 13 insertions, 43 deletions
diff --git a/gcc/cp/error.c b/gcc/cp/error.c index e0e5ae52ceb..3d9f1424685 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -78,14 +78,12 @@ static void dump_global_iord (tree); static void dump_parameters (tree, int); static void dump_exception_spec (tree, int); static void dump_template_argument (tree, int); -static void dump_template_argument_list (tree, tree, int); +static void dump_template_argument_list (tree, int); static void dump_template_parameter (tree, int); static void dump_template_bindings (tree, tree, VEC(tree,gc) *); static void dump_scope (tree, int); static void dump_template_parms (tree, int, int); - -static int count_non_default_template_args (tree, tree, int); - +static int get_non_default_template_args_count (tree, int); static const char *function_category (tree); static void maybe_print_instantiation_context (diagnostic_context *); static void print_instantiation_full_context (diagnostic_context *); @@ -147,7 +145,7 @@ static void dump_template_argument (tree arg, int flags) { if (ARGUMENT_PACK_P (arg)) - dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), NULL_TREE, flags); + dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), flags); else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL) dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM); else @@ -163,52 +161,29 @@ dump_template_argument (tree arg, int flags) match the (optional) default template parameter in PARAMS */ static int -count_non_default_template_args (tree args, tree params, int flags) +get_non_default_template_args_count (tree args, int flags) { - tree inner_args = INNERMOST_TEMPLATE_ARGS (args); - int n = TREE_VEC_LENGTH (inner_args); - int last; + int n = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args)); - if (params == NULL_TREE - /* We use this flag when generating debug information. We don't + if (/* We use this flag when generating debug information. We don't want to expand templates at this point, for this may generate new decls, which gets decl counts out of sync, which may in turn cause codegen differences between compilations with and without -g. */ - || (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0 + (flags & TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS) != 0 || !flag_pretty_templates) return n; - for (last = n - 1; last >= 0; --last) - { - tree param = TREE_VEC_ELT (params, last); - tree def = TREE_PURPOSE (param); - - if (!def) - break; - if (uses_template_parms (def)) - { - ++processing_template_decl; - /* This speculative substitution must not cause any classes to be - instantiated that otherwise wouldn't be. */ - def = tsubst_copy_and_build (def, args, tf_no_class_instantiations, - NULL_TREE, false, true); - --processing_template_decl; - } - if (!cp_tree_equal (TREE_VEC_ELT (inner_args, last), def)) - break; - } - - return last + 1; + return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args)); } /* Dump a template-argument-list ARGS (always a TREE_VEC) under control of FLAGS. */ static void -dump_template_argument_list (tree args, tree parms, int flags) +dump_template_argument_list (tree args, int flags) { - int n = count_non_default_template_args (args, parms, flags); + int n = get_non_default_template_args_count (args, flags); int need_comma = 0; int i; @@ -422,7 +397,7 @@ dump_type (tree t, int flags) pp_cxx_cv_qualifier_seq (cxx_pp, t); pp_cxx_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t)); pp_cxx_begin_template_argument_list (cxx_pp); - dump_template_argument_list (args, NULL_TREE, flags); + dump_template_argument_list (args, flags); pp_cxx_end_template_argument_list (cxx_pp); } break; @@ -1041,7 +1016,7 @@ dump_decl (tree t, int flags) dump_decl (name, flags); pp_cxx_begin_template_argument_list (cxx_pp); if (TREE_OPERAND (t, 1)) - dump_template_argument_list (TREE_OPERAND (t, 1), NULL_TREE, flags); + dump_template_argument_list (TREE_OPERAND (t, 1), flags); pp_cxx_end_template_argument_list (cxx_pp); } break; @@ -1487,12 +1462,7 @@ dump_template_parms (tree info, int primary, int flags) if (args && !primary) { int len, ix; - /* We don't know the parms for a friend template specialization. */ - tree params = (TREE_CODE (TI_TEMPLATE (info)) == TEMPLATE_DECL - ? DECL_INNERMOST_TEMPLATE_PARMS (TI_TEMPLATE (info)) - : NULL_TREE); - - len = count_non_default_template_args (args, params, flags); + len = get_non_default_template_args_count (args, flags); args = INNERMOST_TEMPLATE_ARGS (args); for (ix = 0; ix != len; ix++) |