diff options
author | Jason Merrill <jason@redhat.com> | 2022-02-16 14:05:39 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-02-17 16:22:27 -0500 |
commit | c352ef0ed90cfc07d494dfec111121bc683e337b (patch) | |
tree | 0c14058aac3509d668d643c748d6077570a80b0d /gcc/cp/semantics.cc | |
parent | efbb17db52afd802300c4dcce208fab326ec2915 (diff) | |
download | gcc-c352ef0ed90cfc07d494dfec111121bc683e337b.zip gcc-c352ef0ed90cfc07d494dfec111121bc683e337b.tar.gz gcc-c352ef0ed90cfc07d494dfec111121bc683e337b.tar.bz2 |
c++: avoid duplicate deprecated warning [PR90451]
We were getting the deprecated warning twice for the same call because we
called mark_used first in finish_qualified_id_expr and then again in
build_over_call. Let's not call it the first time; C++17 clarified that a
function is used only when it is selected from an overload set, which
happens later.
Then I had to add a few more uses in places that don't do anything further
with the expression (convert_to_void, finish_decltype_type), and places that
use the expression more unusually (cp_build_addr_expr_1,
convert_nontype_argument). The new mark_single_function is mostly so
that I only have to put the comment in one place.
PR c++/90451
gcc/cp/ChangeLog:
* decl2.cc (mark_single_function): New.
* cp-tree.h: Declare it.
* typeck.cc (cp_build_addr_expr_1): mark_used when making a PMF.
* semantics.cc (finish_qualified_id_expr): Not here.
(finish_id_expression_1): Or here.
(finish_decltype_type): Call mark_single_function.
* cvt.cc (convert_to_void): And here.
* pt.cc (convert_nontype_argument): And here.
* init.cc (build_offset_ref): Adjust assert.
gcc/testsuite/ChangeLog:
* g++.dg/warn/deprecated-14.C: New test.
* g++.dg/warn/deprecated-15.C: New test.
Diffstat (limited to 'gcc/cp/semantics.cc')
-rw-r--r-- | gcc/cp/semantics.cc | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 114baa4..a2c0eb0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2319,7 +2319,10 @@ finish_qualified_id_expr (tree qualifying_class, if (error_operand_p (expr)) return error_mark_node; - if ((DECL_P (expr) || BASELINK_P (expr)) + if (DECL_P (expr) + /* Functions are marked after overload resolution; avoid redundant + warnings. */ + && TREE_CODE (expr) != FUNCTION_DECL && !mark_used (expr, complain)) return error_mark_node; @@ -4198,9 +4201,6 @@ finish_id_expression_1 (tree id_expression, decl = (adjust_result_of_qualified_name_lookup (decl, scope, current_nonlambda_class_type())); - if (TREE_CODE (decl) == FUNCTION_DECL) - mark_used (decl); - cp_warn_deprecated_use_scopes (scope); if (TYPE_P (scope)) @@ -4232,18 +4232,6 @@ finish_id_expression_1 (tree id_expression, tree first_fn = get_first_fn (decl); first_fn = STRIP_TEMPLATE (first_fn); - /* [basic.def.odr]: "A function whose name appears as a - potentially-evaluated expression is odr-used if it is the unique - lookup result". - - But only mark it if it's a complete postfix-expression; in a call, - ADL might select a different function, and we'll call mark_used in - build_over_call. */ - if (done - && !really_overloaded_fn (decl) - && !mark_used (first_fn)) - return error_mark_node; - if (!template_arg_p && (TREE_CODE (first_fn) == USING_DECL || (TREE_CODE (first_fn) == FUNCTION_DECL @@ -11252,6 +11240,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, /* The type denoted by decltype(e) is defined as follows: */ expr = resolve_nondeduced_context (expr, complain); + if (!mark_single_function (expr, complain)) + return error_mark_node; if (invalid_nonstatic_memfn_p (input_location, expr, complain)) return error_mark_node; |