From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CB7F3858D20; Tue, 20 Feb 2024 14:14:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CB7F3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708438452; bh=FVN6k1YBWr6PswoC5zdGm1vbrJVXh/tCjL9SR+E4PlI=; h=From:To:Subject:Date:From; b=HMeXE3Of2YIPxIFGY62BKUZsH6z1De1peDqLAndK1AiPTNWplHRNCChhZbwu06im3 CAeBF8Z2Am0d7l0vdcx8MzU3dcIdTMEGj2dZJAHDL67dnvwQr5L+k0HgXqUQR8lkhs fHvsKVso6wx2uf8tyFpNLK1NMfPJ4iP1ywK88IC0= From: "alexandre.poux at coria dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/114012] New: overloaded unary operator called twice Date: Tue, 20 Feb 2024 14:14:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alexandre.poux at coria dot fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114012 Bug ID: 114012 Summary: overloaded unary operator called twice Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: alexandre.poux at coria dot fr Target Milestone: --- Created attachment 57470 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D57470&action=3Dedit a program triggering the duplicate call on unary operator In the attached code, I overloaded assignment (assign) and the unary operat= or '-' (neg) for a custom class The assign subroutine receive a polymorphic argument and the function neg returns a polymorphic result. When a simple `i =3D -i` is supposed to call `neg` and the `assign`, it surprisingly call `neg` twice and then `assign`.=20 Both time `neg` is called with the correct argument (the old value of `i`) = so the result is good anyway. As far as I know, `neg` and `assign` are supposed to be pure (which they are not, due to the print) so this should only induce a performance hit. I've observed this on an up to date Arch linux with core/gcc-fortran 13.2.1= -5 and extra/gcc12-fortran 12.3.0-3.=