From patchwork Wed Mar 16 17:18:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 87285 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 8A2F6B6FE8 for ; Thu, 17 Mar 2011 04:18:19 +1100 (EST) Received: (qmail 1626 invoked by alias); 16 Mar 2011 17:18:17 -0000 Received: (qmail 1617 invoked by uid 22791); 16 Mar 2011 17:18:16 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Mar 2011 17:18:08 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2GHI64W013544 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Mar 2011 13:18:06 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2GHI6rO025717; Wed, 16 Mar 2011 13:18:06 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p2GHI5N6005500; Wed, 16 Mar 2011 13:18:05 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 29E21378CA4; Wed, 16 Mar 2011 11:18:05 -0600 (MDT) From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: RFA: fix PR c/48116 Date: Wed, 16 Mar 2011 11:18:04 -0600 Message-ID: MIME-Version: 1.0 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 patch fixes PR c/48116. The bug is that -Wreturn-type does not follow the documentation. In particular, it should warn for this code, but does not: static void f() {} static void g() { return f(); } I think the bug is that c-typeck.c calls pedwarn with either 0 or OPT_pedantic, but it should use OPT_Wreturn_type in some cases. I am not completely sure this is the correct patch. In particular, this patch chooses to report -Wreturn-type over -pedantic, e.g.: opsy. gcc -pedantic -Wreturn-type --syntax-only q.c q.c: In function ‘y’: q.c:3:16: warning: ISO C forbids ‘return’ with expression, in function returning void [-Wreturn-type] This is a somewhat odd situation, in that both -Wreturn-type and -pedantic must be disabled to eliminate this message. Also, arguably there should be a different message when -pedantic is not given. Bootstrapped and regtested on x86-64 (compile farm). New test case included. I did not check to see whether this is a regression. Tom 2011-03-16 Tom Tromey PR c/48116 * c-typeck.c (c_finish_return): Check warn_return_type. 2011-03-16 Tom Tromey * gcc.dg/Wreturn-type3.c: New file. Index: c-typeck.c =================================================================== --- c-typeck.c (revision 170953) +++ c-typeck.c (working copy) @@ -8628,10 +8628,11 @@ { current_function_returns_null = 1; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) - pedwarn (loc, 0, + pedwarn (loc, warn_return_type ? OPT_Wreturn_type : 0, "% with a value, in function returning void"); else - pedwarn (loc, OPT_pedantic, "ISO C forbids " + pedwarn (loc, warn_return_type ? OPT_Wreturn_type : OPT_pedantic, + "ISO C forbids " "% with expression, in function returning void"); } else Index: testsuite/gcc.dg/Wreturn-type3.c =================================================================== --- testsuite/gcc.dg/Wreturn-type3.c (revision 0) +++ testsuite/gcc.dg/Wreturn-type3.c (revision 0) @@ -0,0 +1,6 @@ +/* PR c/48116 */ +/* { dg-do compile } */ +/* { dg-options "-Wreturn-type" } */ + +static void f() {} +static void g() { return f(); } /* { dg-warning "forbids .return" "missing return" } */