From patchwork Thu Dec 9 18:43:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 74958 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 EC4EBB6EE8 for ; Fri, 10 Dec 2010 05:43:35 +1100 (EST) Received: (qmail 3231 invoked by alias); 9 Dec 2010 18:43:33 -0000 Received: (qmail 3223 invoked by uid 22791); 9 Dec 2010 18:43:31 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Dec 2010 18:43:27 +0000 Received: (qmail 25695 invoked from network); 9 Dec 2010 18:43:25 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 9 Dec 2010 18:43:25 -0000 Date: Thu, 9 Dec 2010 13:43:22 -0500 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [PATCH,c++] tidy error-handling in cp/typeck2.c Message-ID: <20101209184321.GL25904@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 The patch below pulls out some common diagnostic code about composite pointer operations into its own function. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan * typeck.c (composite_pointer_error): New function. (composite_pointer_type_r, composite_pointer_type): Call it. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7416f09..a4bbd4e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -443,6 +443,35 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2) return cp_common_type (t1, t2); } +static void +composite_pointer_error (diagnostic_t kind, tree t1, tree t2, + composite_pointer_operation operation) +{ + switch (operation) + { + case CPO_COMPARISON: + emit_diagnostic (kind, input_location, 0, + "comparison between " + "distinct pointer types %qT and %qT lacks a cast", + t1, t2); + break; + case CPO_CONVERSION: + emit_diagnostic (kind, input_location, 0, + "conversion between " + "distinct pointer types %qT and %qT lacks a cast", + t1, t2); + break; + case CPO_CONDITIONAL_EXPR: + emit_diagnostic (kind, input_location, 0, + "conditional expression between " + "distinct pointer types %qT and %qT lacks a cast", + t1, t2); + break; + default: + gcc_unreachable (); + } +} + /* Subroutine of composite_pointer_type to implement the recursive case. See that function for documentation of the parameters. */ @@ -486,28 +515,8 @@ composite_pointer_type_r (tree t1, tree t2, else { if (complain & tf_error) - { - switch (operation) - { - case CPO_COMPARISON: - permerror (input_location, "comparison between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - case CPO_CONVERSION: - permerror (input_location, "conversion between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - case CPO_CONDITIONAL_EXPR: - permerror (input_location, "conditional expression between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - default: - gcc_unreachable (); - } - } + composite_pointer_error (DK_PERMERROR, t1, t2, operation); + result_type = void_type_node; } result_type = cp_build_qualified_type (result_type, @@ -520,28 +529,7 @@ composite_pointer_type_r (tree t1, tree t2, if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1), TYPE_PTRMEM_CLASS_TYPE (t2)) && (complain & tf_error)) - { - switch (operation) - { - case CPO_COMPARISON: - permerror (input_location, "comparison between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - case CPO_CONVERSION: - permerror (input_location, "conversion between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - case CPO_CONDITIONAL_EXPR: - permerror (input_location, "conditional expression between " - "distinct pointer types %qT and %qT lacks a cast", - t1, t2); - break; - default: - gcc_unreachable (); - } - } + composite_pointer_error (DK_PERMERROR, t1, t2, operation); result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1), result_type); } @@ -662,23 +650,7 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2, else { if (complain & tf_error) - switch (operation) - { - case CPO_COMPARISON: - error ("comparison between distinct " - "pointer types %qT and %qT lacks a cast", t1, t2); - break; - case CPO_CONVERSION: - error ("conversion between distinct " - "pointer types %qT and %qT lacks a cast", t1, t2); - break; - case CPO_CONDITIONAL_EXPR: - error ("conditional expression between distinct " - "pointer types %qT and %qT lacks a cast", t1, t2); - break; - default: - gcc_unreachable (); - } + composite_pointer_error (DK_ERROR, t1, t2, operation); return error_mark_node; } }