From 0e4cf8872a7f2e74c9905f2aeef75b918f5c8d80 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 7 Mar 2014 15:00:20 -0500 Subject: [PATCH] cp-tree.h (REF_PARENTHESIZED_P): New. * cp-tree.h (REF_PARENTHESIZED_P): New. * semantics.c (force_paren_expr): Set it. * pt.c (do_auto_deduction): Check it. (tsubst) [COMPONENT_REF]: Copy it. * typeck.c (maybe_warn_about_useless_cast): Don't strip dereference. From-SVN: r208412 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cp-tree.h | 7 +++++++ gcc/cp/pt.c | 20 +++++++++++++++----- gcc/cp/semantics.c | 11 +++++++++-- gcc/cp/typeck.c | 5 ++++- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 988c3bf264f7..f617c622fc14 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2014-03-07 Jason Merrill + * cp-tree.h (REF_PARENTHESIZED_P): New. + * semantics.c (force_paren_expr): Set it. + * pt.c (do_auto_deduction): Check it. + (tsubst) [COMPONENT_REF]: Copy it. + * typeck.c (maybe_warn_about_useless_cast): Don't strip dereference. + * decl.c (create_array_type_for_decl): Only warn about invalid C++1y VLA if flag_iso or warn_vla>0. (grokdeclarator): Likewise. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8ec7d6aea1d9..45e4d8217460 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -100,6 +100,7 @@ c-common.h, not after. TARGET_EXPR_DIRECT_INIT_P (in TARGET_EXPR) FNDECL_USED_AUTO (in FUNCTION_DECL) DECLTYPE_FOR_LAMBDA_PROXY (in DECLTYPE_TYPE) + REF_PARENTHESIZED_P (in COMPONENT_REF, SCOPE_REF) 3: (TREE_REFERENCE_EXPR) (in NON_LVALUE_EXPR) (commented-out). ICS_BAD_FLAG (in _CONV) FN_TRY_BLOCK_P (in TRY_BLOCK) @@ -3031,6 +3032,12 @@ extern void decl_shadowed_for_var_insert (tree, tree); #define PAREN_STRING_LITERAL_P(NODE) \ TREE_LANG_FLAG_0 (STRING_CST_CHECK (NODE)) +/* Indicates whether a COMPONENT_REF has been parenthesized. Currently + only set some of the time in C++14 mode. */ + +#define REF_PARENTHESIZED_P(NODE) \ + TREE_LANG_FLAG_2 (COMPONENT_REF_CHECK (NODE)) + /* Nonzero if this AGGR_INIT_EXPR provides for initialization via a constructor call, rather than an ordinary function call. */ #define AGGR_INIT_VIA_CTOR_P(NODE) \ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6476d8aae56e..d4d54b8984d8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14915,6 +14915,7 @@ tsubst_copy_and_build (tree t, tree object; tree object_type; tree member; + tree r; object = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0), args, complain, in_decl); @@ -14999,11 +15000,19 @@ tsubst_copy_and_build (tree t, RETURN (error_mark_node); } else if (TREE_CODE (member) == FIELD_DECL) - RETURN (finish_non_static_data_member (member, object, NULL_TREE)); + { + r = finish_non_static_data_member (member, object, NULL_TREE); + if (TREE_CODE (r) == COMPONENT_REF) + REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); + RETURN (r); + } - RETURN (finish_class_member_access_expr (object, member, - /*template_p=*/false, - complain)); + r = finish_class_member_access_expr (object, member, + /*template_p=*/false, + complain); + if (TREE_CODE (r) == COMPONENT_REF) + REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); + RETURN (r); } case THROW_EXPR: @@ -21619,7 +21628,8 @@ do_auto_deduction (tree type, tree init, tree auto_node) targs = make_tree_vec (1); if (AUTO_IS_DECLTYPE (auto_node)) { - bool id = (DECL_P (init) || TREE_CODE (init) == COMPONENT_REF); + bool id = (DECL_P (init) || (TREE_CODE (init) == COMPONENT_REF + && !REF_PARENTHESIZED_P (init))); TREE_VEC_ELT (targs, 0) = finish_decltype_type (init, id, tf_warning_or_error); if (type != auto_node) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index b9c1271e3898..fcd840956572 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1605,11 +1605,18 @@ force_paren_expr (tree expr) if (cxx_dialect < cxx1y) return expr; + /* If we're in unevaluated context, we can't be deducing a + return/initializer type, so we don't need to mess with this. */ + if (cp_unevaluated_operand) + return expr; + if (!DECL_P (expr) && TREE_CODE (expr) != COMPONENT_REF && TREE_CODE (expr) != SCOPE_REF) return expr; - if (type_dependent_expression_p (expr)) + if (TREE_CODE (expr) == COMPONENT_REF) + REF_PARENTHESIZED_P (expr) = true; + else if (type_dependent_expression_p (expr)) expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr); else { @@ -1619,7 +1626,7 @@ force_paren_expr (tree expr) tree type = unlowered_expr_type (expr); bool rval = !!(kind & clk_rvalueref); type = cp_build_reference_type (type, rval); - expr = build_static_cast (type, expr, tf_warning_or_error); + expr = build_static_cast (type, expr, tf_error); } } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c91612c76754..d8374d9b0b4e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6291,7 +6291,10 @@ maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain) if (warn_useless_cast && complain & tf_warning) { - if (REFERENCE_REF_P (expr)) + /* In C++14 mode, this interacts badly with force_paren_expr. And it + isn't necessary in any mode, because the code below handles + glvalues properly. For 4.9, just skip it in C++14 mode. */ + if (cxx_dialect < cxx1y && REFERENCE_REF_P (expr)) expr = TREE_OPERAND (expr, 0); if ((TREE_CODE (type) == REFERENCE_TYPE -- 2.47.2