From patchwork Sun Jul 18 11:45:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 59162 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 88E2EB70A5 for ; Sun, 18 Jul 2010 21:45:35 +1000 (EST) Received: (qmail 9758 invoked by alias); 18 Jul 2010 11:45:34 -0000 Received: (qmail 9746 invoked by uid 22791); 18 Jul 2010 11:45:32 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, TW_XG X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 18 Jul 2010 11:45:27 +0000 Received: by wye20 with SMTP id 20so4170681wye.20 for ; Sun, 18 Jul 2010 04:45:25 -0700 (PDT) Received: by 10.227.94.138 with SMTP id z10mr2827886wbm.166.1279453525381; Sun, 18 Jul 2010 04:45:25 -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 e31sm31579591wbe.17.2010.07.18.04.45.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 18 Jul 2010 04:45:24 -0700 (PDT) Message-Id: <0998E12D-76DF-48FE-B1B2-BC5837F192B0@sandoe-acoustics.co.uk> From: IainS To: gcc-patches List Mime-Version: 1.0 (Apple Message framework v936) Subject: [Patch, attribute(deprecated)] fix PR43797. Date: Sun, 18 Jul 2010 12:45:21 +0100 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 this: typedef int INT1 __attribute__((deprecated("No INT1"))); INT1 f1 (void) __attribute__((deprecated("No f1"))); INT1 f2 (void) __attribute__((deprecated)); void func (void) { f1(); f2(); } should print : 'f1' is deprecated .....: No f1 'f2' is deprecated ..... but with trunk the second message is incorrectly: 'f2' is deprecated ..... : No INT1. ---- the following has been bootstrapped & regtested on i686-apple-darwin9 and checked to give the correct answer with: xgcc, g++, xgcc -x objective-c and xgcc -x objective-c++ (g++/ObjC++ modulo the issues of duplicated warnings, which is a + /* { dg-warning "'f2' is deprecated .declared at \[^\\)\]*." "f2" { target *-*-* } 11 } */ +} different PR) I have only attached a testcase to "C" since the principal change is in common code. OK for trunk? Iain ---- gcc/ PR c/43797 * toplev.c: Handle deprecated attribute search consistently. gcc/c-family PR c/43797 * c-common.c: Attach __attribute__(deprecated), even when there is no deprecation advice message. testsuite/ PR c/43797 * gcc.dg/pr43797.c: New. === Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 162282) +++ gcc/toplev.c (working copy) @@ -867,15 +867,16 @@ warn_deprecated_use (tree node, tree attr) { tree decl = TYPE_STUB_DECL (node); if (decl) - attr = lookup_attribute ("deprecated", - TYPE_ATTRIBUTES (TREE_TYPE (decl))); + attr = TYPE_ATTRIBUTES (TREE_TYPE (decl)); + else + attr = TYPE_ATTRIBUTES (node); } } if (attr) attr = lookup_attribute ("deprecated", attr); - if (attr) + if (attr && TREE_VALUE (attr) && TREE_VALUE (TREE_VALUE (attr))) msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); else msg = NULL; Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 162282) +++ gcc/c-family/c-common.c (working copy) @@ -7115,13 +7115,8 @@ handle_deprecated_attribute (tree *node, tree name int warn = 0; tree what = NULL_TREE; - if (!args) - *no_add_attrs = true; - else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) - { - error ("deprecated message is not a string"); - *no_add_attrs = true; - } + if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST) + error ("deprecated message is not a string"); if (DECL_P (*node)) { Index: gcc/testsuite/gcc.dg/pr43797.c =================================================================== --- gcc/testsuite/gcc.dg/pr43797.c (revision 0) +++ gcc/testsuite/gcc.dg/pr43797.c (revision 0) @@ -0,0 +1,13 @@ +/* pr 43797 */ +/* dg-do compile */ + +typedef int INT1 __attribute__((deprecated("No INT1"))); +INT1 f1 (void) __attribute__((deprecated("No f1"))); +INT1 f2 (void) __attribute__((deprecated)); + +void func (void) +{ + f1(); /* { dg-warning "'f1' is deprecated .declared at \[^\\)\]*.: No f1" "f1" } */ + f2(); /* { dg-bogus "'f2' is deprecated .declared at \[^\\)\]*.: No INT1" "f2-wrong deprecation message" } */