From patchwork Mon Jul 19 17:11:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 59212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2A632B6EED for ; Tue, 20 Jul 2010 03:11:28 +1000 (EST) Received: (qmail 17431 invoked by alias); 19 Jul 2010 17:11:26 -0000 Received: (qmail 17380 invoked by uid 22791); 19 Jul 2010 17:11:24 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 19 Jul 2010 17:11:19 +0000 Received: by wwe15 with SMTP id 15so475024wwe.8 for ; Mon, 19 Jul 2010 10:11:16 -0700 (PDT) Received: by 10.227.153.3 with SMTP id i3mr2693547wbw.171.1279559476730; Mon, 19 Jul 2010 10:11:16 -0700 (PDT) Received: from thor.office (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by mx.google.com with ESMTPS id a27sm42365502wbe.6.2010.07.19.10.11.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 19 Jul 2010 10:11:15 -0700 (PDT) Cc: GCC Patches , "Joseph S. Myers" Message-Id: <3EC5B677-F737-4B70-AB06-460A97AF915C@sandoe-acoustics.co.uk> From: IainS To: Jason Merrill In-Reply-To: <4C0F0855.3060005@redhat.com> Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: [Patch c++] (__attribute__((deprecated)), part a) Fix PR17729 Date: Mon, 19 Jul 2010 18:11:10 +0100 References: <8E1F6759-A426-494D-8B3B-58FDF04BFB1A@sandoe-acoustics.co.uk> <4C0EC931.6010106@redhat.com> <4C0F0855.3060005@redhat.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi Jason, It's taken a while to find some more time for this - (ObJC LTO and emutls.... etc. etc.) On 9 Jun 2010, at 04:19, Jason Merrill wrote: > On 06/08/2010 07:13 PM, IainS wrote: >> the question then, is how to prevent the duplicates, since those >> places >> are called from more than one part of the process (or, at least, they >> were when I last looked). > > For non-function members, I think removing the call in > finish_class_member_access_expr ought to do the trick, letting > build_class_member_access_expr handle the warning. done > For functions, perhaps just warning in mark_used would work. Then > removing the calls in build_over_call and build_call_a and > conditioning the one in finish_id_expression on !is_overloaded_fn. unfortunately, not mark_used is called even more often than build_over_call & build_call_a (at one stage I ended up with three warning messages)... It seems that there is no nice place to put these diagnostics, that is only visited once (for the current formulation***); Hence we end up checking in several places (which, I agree, does not seem ideal). The attached patch has been bootstrapped/checked on i686-apple-darwin9 I've added a test-case for overloaded functions, member funcs are covered in deprecated-{4,6} iirc. thoughts? Iain *** It seems to me that the diagnostics might be better done at the stage that the parser has decided that (other than deprecation) a given construct is OK. (I guess just before swallowing the ";"). However, I don't know if this is reasonable, &| there would be enough information preserved to make the diagnostic neat (although it seems that there should). gcc/cp: PR c++/17729 * typeck.c (finish_class_member_access_expr): Remove duplicate deprecation check. * call.c (build_call_a): Do not check deprecation here. (build_over_call): Ditto. (build_new_function_call): Check for deprecated overloaded funcs here. (convert_like_real): Check for deprecated functions. (build_new_method_call): Ditto. gcc/testsuite: PR c++/17729 * g++.dg/warn/pr17729-1-fields.C: New. * g++.dg/warn/pr17729-2-funcs.C: New. * g++.dg/warn/deprecated-7.C: New. \ No newline at end of file Index: gcc/cp/typeck.c =================================================================== --- gcc/cp/typeck.c (revision 162309) +++ gcc/cp/typeck.c (working copy) @@ -2692,9 +2692,6 @@ finish_class_member_access_expr (tree object, tree } } - if (TREE_DEPRECATED (member)) - warn_deprecated_use (member, NULL_TREE); - if (template_p) check_template_keyword (member); Index: gcc/cp/call.c =================================================================== --- gcc/cp/call.c (revision 162309) +++ gcc/cp/call.c (working copy) @@ -347,8 +347,6 @@ build_call_a (tree function, int n, tree *argarray if (decl && TREE_THIS_VOLATILE (decl) && cfun && cp_function_chain) current_function_returns_abnormally = 1; - if (decl && TREE_DEPRECATED (decl)) - warn_deprecated_use (decl, NULL_TREE); require_complete_eh_spec_types (fntype, decl); if (decl && DECL_CONSTRUCTOR_P (decl)) @@ -3283,8 +3281,11 @@ build_new_function_call (tree fn, VEC(tree,gc) **a result = error_mark_node; } else - result = build_over_call (cand, LOOKUP_NORMAL, complain); - + { + if (koenig_p && TREE_DEPRECATED (cand->fn)) + warn_deprecated_use (cand->fn, NULL_TREE); + result = build_over_call (cand, LOOKUP_NORMAL, complain); + } /* Free all the conversions we allocated. */ obstack_free (&conversion_obstack, p); @@ -5018,6 +5019,10 @@ convert_like_real (conversion *convs, tree expr, t for (i = 0; i < cand->num_convs; ++i) cand->convs[i]->user_conv_p = true; + /* Warn on deprecation of the candidate conversion func. */ + if (TREE_DEPRECATED (convfn)) + warn_deprecated_use (convfn, NULL_TREE); + expr = build_over_call (cand, LOOKUP_NORMAL, complain); /* If this is a constructor or a function returning an aggr type, @@ -6010,11 +6015,6 @@ build_over_call (struct z_candidate *cand, int fla ba_any, NULL); gcc_assert (binfo && binfo != error_mark_node); - /* Warn about deprecated virtual functions now, since we're about - to throw away the decl. */ - if (TREE_DEPRECATED (fn)) - warn_deprecated_use (fn, NULL_TREE); - argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1); if (TREE_SIDE_EFFECTS (argarray[0])) argarray[0] = save_expr (argarray[0]); @@ -6575,6 +6575,11 @@ build_new_method_call (tree instance, tree fns, VE /* Now we know what function is being called. */ if (fn_p) *fn_p = fn; + + /* Check for deprecation of the function to be called. */ + if (TREE_DEPRECATED (fn)) + warn_deprecated_use (fn, NULL_TREE); + /* Build the actual CALL_EXPR. */ call = build_over_call (cand, flags, complain); /* In an expression of the form `a->f()' where `f' turns Index: gcc/testsuite/g++.dg/warn/pr17729-2-funcs.C =================================================================== --- gcc/testsuite/g++.dg/warn/pr17729-2-funcs.C (revision 0) +++ gcc/testsuite/g++.dg/warn/pr17729-2-funcs.C (revision 0) @@ -0,0 +1,9 @@ +/* PR 17729 */ +/* { dg-do compile } */ +int fun (void) __attribute__((deprecated("no fun"))) ; + +void foo (void) +{ + fun (); // { dg-bogus "int fun.* no fun.*int fun" "duplicate func. warning" } + // { dg-warning "'int fun..' is deprecated .declared at \[^\\)\]*.: no fun" "" { target *-*-* } 7 } +} Index: gcc/testsuite/g++.dg/warn/deprecated-7.C =================================================================== --- gcc/testsuite/g++.dg/warn/deprecated-7.C (revision 0) +++ gcc/testsuite/g++.dg/warn/deprecated-7.C (revision 0) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int f1 (int, int); +int f1 (float, int) __attribute__((deprecated("no flt, int"))) ; +int f1 (float, float); + +void foo (void) +{ + int a, b, r; + float c,d; + + r = f1 (a, b); + r = f1 (c, a); // { dg-warning "'int f1.float, int.' is deprecated .declared at \[^\\)\]*.: no flt, int" } + r = f1 (c, d); + +} \ No newline at end of file Index: gcc/testsuite/g++.dg/warn/pr17729-1-fields.C =================================================================== --- gcc/testsuite/g++.dg/warn/pr17729-1-fields.C (revision 0) +++ gcc/testsuite/g++.dg/warn/pr17729-1-fields.C (revision 0) @@ -0,0 +1,20 @@ +/* PR 17729 */ +/* { dg-do compile } */ +typedef int INT1 __attribute__((deprecated("no INT1"))) ; + +struct _a { + int field1 ; + int field2 __attribute__((deprecated("no field2"))) ; + INT1 field3; /* { dg-warning "'INT1' is deprecated .declared \[^\\)\]*.: no INT1 " } */ + INT1 field4 __attribute__((deprecated("no field4"))); /* { dg-warning "'INT1' is deprecated .declared .* no INT1 " } */ +} s; + +void foo (void) +{ + s.field1 = 1; + s.field2 = 2; // { dg-bogus "_a::field2.*_a::field2" "duplicate field warning" } + // { dg-warning "'_a::field2' is deprecated .declared at \[^\\)\]*.: no field2" "" { target *-*-* } 15 } + s.field3 = 3; + s.field4 = 4; // { dg-bogus "_a::field4.*_a::field4" "duplicate field warning" } + // { dg-warning "'_a::field4' is deprecated .declared at .* no field4" "" { target *-*-* } 18 } +}