diff options
author | Jason Merrill <jason@redhat.com> | 2021-11-03 09:29:47 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-11-22 17:43:10 -0500 |
commit | 1df539fd197ef2427bdfa27156b92d2a857af949 (patch) | |
tree | 6c26231326dd01d472b8062465ec3a2f6f3fc92f /gcc/cp | |
parent | 5440c88e61f5c624eb87e19801eef6eedf27e8ab (diff) | |
download | gcc-1df539fd197ef2427bdfa27156b92d2a857af949.zip gcc-1df539fd197ef2427bdfa27156b92d2a857af949.tar.gz gcc-1df539fd197ef2427bdfa27156b92d2a857af949.tar.bz2 |
c++: remember pointer-to-member location
Jakub recently mentioned that a PTRMEM_CST has no location; let's give it a
location wrapper.
gcc/cp/ChangeLog:
* typeck.c (build_x_unary_op): Set address location.
(convert_member_func_to_ptr): Handle location wrapper.
* pt.c (convert_nontype_argument): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/template/crash106.C: Adjust.
* g++.dg/diagnostic/ptrtomem3.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/pt.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c73e035..288625e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7267,6 +7267,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) const bool val_dep_p = value_dependent_expression_p (expr); if (val_dep_p) expr = canonicalize_expr_argument (expr, complain); + else + STRIP_ANY_LOCATION_WRAPPER (expr); /* 14.3.2/5: The null pointer{,-to-member} conversion is applied to a non-type argument of "nullptr". */ diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 63a0eae..84dcb6f 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6492,6 +6492,11 @@ build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg, } exp = cp_build_addr_expr_strict (xarg, complain); + + if (TREE_CODE (exp) == PTRMEM_CST) + exp = maybe_wrap_with_location (exp, loc); + else + protected_set_expr_location (exp, loc); } if (processing_template_decl && exp != error_mark_node) @@ -8179,10 +8184,14 @@ convert_member_func_to_ptr (tree type, tree expr, tsubst_flags_t complain) if (!(complain & tf_warning_or_error)) return error_mark_node; + location_t loc = cp_expr_loc_or_input_loc (expr); + if (pedantic || warn_pmf2ptr) - pedwarn (input_location, pedantic ? OPT_Wpedantic : OPT_Wpmf_conversions, + pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpmf_conversions, "converting from %qH to %qI", intype, type); + STRIP_ANY_LOCATION_WRAPPER (expr); + if (TREE_CODE (intype) == METHOD_TYPE) expr = build_addr_func (expr, complain); else if (TREE_CODE (expr) == PTRMEM_CST) @@ -8197,7 +8206,9 @@ convert_member_func_to_ptr (tree type, tree expr, tsubst_flags_t complain) if (expr == error_mark_node) return error_mark_node; - return build_nop (type, expr); + expr = build_nop (type, expr); + SET_EXPR_LOCATION (expr, loc); + return expr; } /* Build a NOP_EXPR to TYPE, but mark it as a reinterpret_cast so that |