diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 220ac130b0b..3033be47c7d 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -10004,6 +10004,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) SET_EXPR_LOCATION (expr, input_location); if (TREE_THIS_VOLATILE (fn) && cfun) current_function_returns_abnormally = 1; + if (TREE_DEPRECATED (fn) + && warning_suppressed_at (input_location, + OPT_Wdeprecated_declarations)) + /* Make the expr consistent with the location. */ + TREE_NO_WARNING (expr) = true; if (immediate_invocation_p (fn)) { tree obj_arg = NULL_TREE, exprimm = expr; @@ -10704,6 +10709,14 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (TREE_CODE (c) == CALL_EXPR) suppress_warning (c /* Suppress all warnings. */); } + else if (TREE_DEPRECATED (fn) + && warning_suppressed_at (input_location, + OPT_Wdeprecated_declarations)) + { + tree c = extract_call_expr (call); + if (TREE_CODE (c) == CALL_EXPR) + TREE_NO_WARNING (c) = true; + } return call; } diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index fdcd67d5406..5f176168309 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -5943,7 +5943,12 @@ cp_handle_deprecated_or_unavailable (tree decl, tsubst_flags_t complain) } } else - warned = warn_deprecated_use (decl, NULL_TREE); + { + if (!warning_suppressed_at (input_location, + OPT_Wdeprecated_declarations)) + warned = warn_deprecated_use (decl, NULL_TREE); + suppress_warning_at (input_location, OPT_Wdeprecated_declarations); + } return warned; } diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cb2b1543462..ecdd3da9ea2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -3313,11 +3313,12 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, orig_fn = sel_fn; } - result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); - SET_EXPR_LOCATION (result, input_location); - KOENIG_LOOKUP_P (result) = koenig_p; + tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); + SET_EXPR_LOCATION (r, input_location); + KOENIG_LOOKUP_P (r) = koenig_p; + TREE_NO_WARNING (r) = TREE_NO_WARNING (result); release_tree_vector (orig_args); - result = convert_from_reference (result); + result = convert_from_reference (r); } return result; diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-2_a.C b/gcc/testsuite/g++.dg/modules/warn-spec-2_a.C new file mode 100644 index 00000000000..fbfa668b2c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/warn-spec-2_a.C @@ -0,0 +1,11 @@ +// { dg-additional-options -fmodules } + +export module M; + +[[deprecated]] void depr_fn() {} + +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +export { + template void f(T) { depr_fn(); } +} diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-2_b.C b/gcc/testsuite/g++.dg/modules/warn-spec-2_b.C new file mode 100644 index 00000000000..437748b1332 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/warn-spec-2_b.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules } + +import M; + +int main() +{ + f(42); +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated-21.C b/gcc/testsuite/g++.dg/warn/deprecated-21.C new file mode 100644 index 00000000000..7454a12c57b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-21.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } + +[[deprecated]] void depr_fn() {} + +template void f(T) { + depr_fn(); // { dg-warning "deprecated" } +} + +int main() +{ + f(42); +} diff --git a/gcc/warning-control.cc b/gcc/warning-control.cc index 11ca5db69c3..a13c3143897 100644 --- a/gcc/warning-control.cc +++ b/gcc/warning-control.cc @@ -262,7 +262,7 @@ copy_warning (gimple *to, const gimple *from) bool has_warning_spec (const_tree t) { const location_t loc = get_location (t); - return !RESERVED_LOCATION_P (loc) && !get_no_warning_bit (t); + return !RESERVED_LOCATION_P (loc) && get_no_warning_bit (t); } /* Retrieve warning dispostion bitmap for tree streaming. */