From patchwork Sat Jun 9 16:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 927178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-479392-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bCO0df2h"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4133tR12r8z9ry1 for ; Sun, 10 Jun 2018 02:01:33 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=Hpw1dXBOLIgK2p9+Xyc76NxsOlsFB1kngRRAkQDk1Rv RTNEC6xketxBwkZ/pxYB3k4X7nJob2kHr869ILOnlz8HqHlMHNkvIJjzMaLWw6pT ztaDW3UxszndcJ3QHjTWZ3tICRlWCRWWur5pIx9u5oB2jRGhKMkk3Q37i4Gi9nFs = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=YtAWgEhF6d8KfXxHw6ZblaKdXYU=; b=bCO0df2hiHYHeA3j+ bh1dhjZ/C59DFyHn4etRtHnccyaSwObBgHkefGqhB+WbgIkhro1tlCHxSw8To1Bi rXOOgVl0kwP7tR1xu8+n/q1gLifFDjkvYgeN8H3pUhVlKIyESrzdV5VHbnSetHsp +Sen+77K8ujY98VaN+ViFRXO2Q= Received: (qmail 86881 invoked by alias); 9 Jun 2018 16:01:21 -0000 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 Received: (qmail 72963 invoked by uid 89); 9 Jun 2018 16:00:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*F:D*washington.edu X-Spam-User: qpsmtpd, 2 recipients X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Jun 2018 16:00:50 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id w59G0bZU081123 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 9 Jun 2018 09:00:37 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id w59G0bJU081122; Sat, 9 Jun 2018 09:00:37 -0700 (PDT) (envelope-from sgk) Date: Sat, 9 Jun 2018 09:00:37 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Committed] PR fortran/38351 -- Improved error message Message-ID: <20180609160037.GA81073@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) I've committed the attached patch. It provides a better error message (IMO) when a derived-type entity is used in a binary intrinsic numeric operator. 2018-06-09 Steven G. Kargl PR fortran/38351 * resolve.c (resolve_operator): Provide better error message for derived type entity used in an binary intrinsic numeric operator. 2018-06-09 Steven G. Kargl PR fortran/38351 * gfortran.dg/pr38351.f90: New test. * gfortran.dg/typebound_operator_4.f03: Adjust for new error message. Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 261361) +++ gcc/fortran/resolve.c (working copy) @@ -3878,7 +3878,13 @@ resolve_operator (gfc_expr *e) break; } - sprintf (msg, + if (op1->ts.type == BT_DERIVED || op2->ts.type == BT_DERIVED) + sprintf (msg, + _("Unexpected derived-type entities in binary intrinsic " + "numeric operator %%<%s%%> at %%L"), + gfc_op2string (e->value.op.op)); + else + sprintf (msg, _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"), gfc_op2string (e->value.op.op), gfc_typename (&op1->ts), gfc_typename (&op2->ts)); Index: gcc/testsuite/gfortran.dg/pr38351.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr38351.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr38351.f90 (working copy) @@ -0,0 +1,21 @@ +! { dg-do compile } +module m1 + type t1 + integer :: i + end type t1 + interface operator(+) + module procedure add + end interface + contains + type(t1) function add(a,b) + type(t1), intent(in) :: a,b + end function +end module m1 + +program foo + use m1 + type(t1), dimension(2,2) :: a = t1(1), b = t1(2) + type(t1) :: c=t1(1), d=t1(2) + c = c + d + a = a + b ! { dg-error "Unexpected derived-type entities" } +end program foo Index: gcc/testsuite/gfortran.dg/typebound_operator_4.f03 =================================================================== --- gcc/testsuite/gfortran.dg/typebound_operator_4.f03 (revision 261361) +++ gcc/testsuite/gfortran.dg/typebound_operator_4.f03 (working copy) @@ -84,6 +84,6 @@ PROGRAM main TYPE(myint) :: x x = 0 ! { dg-error "Can't convert" } - x = x + 42 ! { dg-error "Operands of" } + x = x + 42 ! { dg-error "binary intrinsic numeric operator" } x = x .PLUS. 5 ! { dg-error "Unknown operator" } END PROGRAM main