From 6904f4b401d50c17b1a0dbd6eac64212700973fa Mon Sep 17 00:00:00 2001 From: David Krauss Date: Fri, 10 Jun 2011 05:18:36 +0000 Subject: [PATCH] re PR c++/49118 (Endless operator-> chain causes infinite loop) PR c++/49118 * typeck2.c (build_x_arrow): Push fake template context to produce diagnostic on acyclic endless operator-> drill-down. * call.c (build_new_op): Change Boolean overload status value to a pointer to the overload function. * cp-tree.h: Likewise. * typeck.c: Likewise. * parser.c: Likewise. * decl2.c: Likewise. * pt.c: Likewise. From-SVN: r174889 --- gcc/cp/ChangeLog | 13 +++++++++++++ gcc/cp/call.c | 12 ++++++------ gcc/cp/cp-tree.h | 4 ++-- gcc/cp/decl2.c | 2 +- gcc/cp/parser.c | 12 +++++------- gcc/cp/pt.c | 2 +- gcc/cp/typeck.c | 18 +++++++++--------- gcc/cp/typeck2.c | 13 +++++++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/arrow1.C | 17 +++++++++++++++++ 10 files changed, 69 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/arrow1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e134c274189..dcea35ad838 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +2011-06-09 David Krauss + + PR c++/49118 + * typeck2.c (build_x_arrow): Push fake template context + to produce diagnostic on acyclic endless operator-> drill-down. + * call.c (build_new_op): Change Boolean overload status + value to a pointer to the overload function. + * cp-tree.h: Likewise. + * typeck.c: Likewise. + * parser.c: Likewise. + * decl2.c: Likewise. + * pt.c: Likewise. + 2011-06-09 Jason Merrill * semantics.c (maybe_constant_value): Handle overflowed input. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d955b63936c..4ee0eafe81d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4791,7 +4791,7 @@ avoid_sign_compare_warnings (tree orig_arg, tree arg) static tree build_new_op_1 (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, - bool *overloaded_p, tsubst_flags_t complain) + tree *overload, tsubst_flags_t complain) { tree orig_arg1 = arg1; tree orig_arg2 = arg2; @@ -4958,7 +4958,7 @@ build_new_op_1 (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, else code = PREDECREMENT_EXPR; result = build_new_op_1 (code, flags, arg1, NULL_TREE, NULL_TREE, - overloaded_p, complain); + overload, complain); break; /* The caller will deal with these. */ @@ -5005,8 +5005,8 @@ build_new_op_1 (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, } else if (TREE_CODE (cand->fn) == FUNCTION_DECL) { - if (overloaded_p) - *overloaded_p = true; + if (overload) + *overload = cand->fn; if (resolve_args (arglist, complain) == NULL) result = error_mark_node; @@ -5165,11 +5165,11 @@ build_new_op_1 (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, tree build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, - bool *overloaded_p, tsubst_flags_t complain) + tree *overload, tsubst_flags_t complain) { tree ret; bool subtime = timevar_cond_start (TV_OVERLOAD); - ret = build_new_op_1 (code, flags, arg1, arg2, arg3, overloaded_p, complain); + ret = build_new_op_1 (code, flags, arg1, arg2, arg3, overload, complain); timevar_cond_stop (TV_OVERLOAD, subtime); return ret; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ce2af0044be..f7bcd0d42de 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4717,7 +4717,7 @@ extern tree build_new_method_call (tree, tree, VEC(tree,gc) **, extern tree build_special_member_call (tree, tree, VEC(tree,gc) **, tree, int, tsubst_flags_t); extern tree build_new_op (enum tree_code, int, tree, - tree, tree, bool *, + tree, tree, tree *, tsubst_flags_t); extern tree build_op_call (tree, VEC(tree,gc) **, tsubst_flags_t); @@ -5611,7 +5611,7 @@ extern tree cp_build_function_call_vec (tree, VEC(tree,gc) **, tsubst_flags_t); extern tree build_x_binary_op (enum tree_code, tree, enum tree_code, tree, - enum tree_code, bool *, + enum tree_code, tree *, tsubst_flags_t); extern tree build_x_array_ref (tree, tree, tsubst_flags_t); extern tree build_x_unary_op (enum tree_code, tree, diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index a0512cdcab2..8eee4588198 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -361,7 +361,7 @@ grok_array_decl (tree array_expr, tree index_exp) if (MAYBE_CLASS_TYPE_P (type) || MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp))) expr = build_new_op (ARRAY_REF, LOOKUP_NORMAL, array_expr, index_exp, NULL_TREE, - /*overloaded_p=*/NULL, tf_warning_or_error); + /*overload=*/NULL, tf_warning_or_error); else { tree p1, p2, i1, i2; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 35f8957aa65..961f9feb800 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6585,7 +6585,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, cp_token *token; enum tree_code tree_type, lhs_type, rhs_type; enum cp_parser_prec new_prec, lookahead_prec; - bool overloaded_p; + tree overload; /* Parse the first expression. */ lhs = cp_parser_cast_expression (parser, /*address_p=*/false, cast_p, pidk); @@ -6688,7 +6688,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, else if (tree_type == TRUTH_ORIF_EXPR) c_inhibit_evaluation_warnings -= lhs == truthvalue_true_node; - overloaded_p = false; + overload = NULL; /* ??? Currently we pass lhs_type == ERROR_MARK and rhs_type == ERROR_MARK for everything that is not a binary expression. This makes warn_about_parentheses miss some warnings that @@ -6703,7 +6703,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, lhs = build2 (tree_type, boolean_type_node, lhs, rhs); else lhs = build_x_binary_op (tree_type, lhs, lhs_type, rhs, rhs_type, - &overloaded_p, tf_warning_or_error); + &overload, tf_warning_or_error); lhs_type = tree_type; /* If the binary operator required the use of an overloaded operator, @@ -6712,7 +6712,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, otherwise permissible in an integral constant-expression if at least one of the operands is of enumeration type. */ - if (overloaded_p + if (overload && cp_parser_non_integral_constant_expression (parser, NIC_OVERLOADED)) return error_mark_node; @@ -24245,8 +24245,6 @@ cp_parser_omp_for_cond (cp_parser *parser, tree decl) { tree cond = cp_parser_binary_expression (parser, false, true, PREC_NOT_OPERATOR, NULL); - bool overloaded_p; - if (cond == error_mark_node || cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) { @@ -24275,7 +24273,7 @@ cp_parser_omp_for_cond (cp_parser *parser, tree decl) return build_x_binary_op (TREE_CODE (cond), TREE_OPERAND (cond, 0), ERROR_MARK, TREE_OPERAND (cond, 1), ERROR_MARK, - &overloaded_p, tf_warning_or_error); + /*overload=*/NULL, tf_warning_or_error); } /* Helper function, to parse omp for increment expression. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ac150cedd64..814a08f6a4e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12753,7 +12753,7 @@ tsubst_copy_and_build (tree t, (TREE_NO_WARNING (TREE_OPERAND (t, 1)) ? ERROR_MARK : TREE_CODE (TREE_OPERAND (t, 1))), - /*overloaded_p=*/NULL, + /*overload=*/NULL, complain); case SCOPE_REF: diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 8e4fd4213c3..1bed291617e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2035,7 +2035,7 @@ rationalize_conditional_expr (enum tree_code code, tree t, ? LE_EXPR : GE_EXPR), op0, TREE_CODE (op0), op1, TREE_CODE (op1), - /*overloaded_p=*/NULL, + /*overload=*/NULL, complain), cp_build_unary_op (code, op0, 0, complain), cp_build_unary_op (code, op1, 0, complain), @@ -2689,7 +2689,7 @@ build_x_indirect_ref (tree expr, ref_operator errorstring, } rval = build_new_op (INDIRECT_REF, LOOKUP_NORMAL, expr, NULL_TREE, - NULL_TREE, /*overloaded_p=*/NULL, complain); + NULL_TREE, /*overload=*/NULL, complain); if (!rval) rval = cp_build_indirect_ref (expr, errorstring, complain); @@ -3497,7 +3497,7 @@ convert_arguments (tree typelist, VEC(tree,gc) **values, tree fndecl, tree build_x_binary_op (enum tree_code code, tree arg1, enum tree_code arg1_code, - tree arg2, enum tree_code arg2_code, bool *overloaded_p, + tree arg2, enum tree_code arg2_code, tree *overload, tsubst_flags_t complain) { tree orig_arg1; @@ -3520,7 +3520,7 @@ build_x_binary_op (enum tree_code code, tree arg1, enum tree_code arg1_code, expr = build_m_component_ref (arg1, arg2); else expr = build_new_op (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE, - overloaded_p, complain); + overload, complain); /* Check for cases such as x+y<%> has non-pointer type %qT", type); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d93c01a2a4e..a1e9ae2dd74 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-06-09 David Krauss + + * g++.dg/template/arrow1.C: New. + 2011-06-09 Jason Merrill * lib/prune.exp: Prune "note"s. diff --git a/gcc/testsuite/g++.dg/template/arrow1.C b/gcc/testsuite/g++.dg/template/arrow1.C new file mode 100644 index 00000000000..c96141063a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/arrow1.C @@ -0,0 +1,17 @@ +// PR c++/49118 +// { dg-do compile } + +template< int n > +struct a { + a< n+1 > + operator->() + { return a< n+1 >(); } +}; + +int main() { + a<0>()->x; // { dg-error "instantiation depth exceeds maximum" } +} + +// { dg-prune-output "incomplete type" } +// { dg-prune-output "declaration of" } +// { dg-prune-output "used but never defined" } -- 2.30.2