public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/109641] Gfortran fails to overload intrinsic operator (*) if operands are complex. It works with real ones.
Date: Fri, 28 Apr 2023 01:15:13 +0000	[thread overview]
Message-ID: <bug-109641-4-vsimsLIBUA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109641-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109641

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #6 from kargl at gcc dot gnu.org ---
(In reply to Adelson Oliveira from comment #5)
> (In reply to anlauf from comment #2)
> > Replacing the first argument of
> > 
> >   FUNCTION MULTc4(v,m)
> >     REAL,    INTENT(IN) :: v(:)
> > 
> > by
> > 
> >     complex, INTENT(IN) :: v(:)
> > 
> > makes the code compile, but should not.  And the fortran-dump appears to
> > explain why: we prematurely convert the first argument in the expression
> > 
> >   r=v*m
> > 
> > from real to complex, so we resolve to the wrong specific.
> > This also explains why real*real does not exhibit this problem.
> 
> Interesting! But I wonder why simply changing the intrinsic operator (*) to
> something different, say (.MULT.) there is no error at all no matter one
> uses complex or real.

The simple and obvious answer is that .multi. is not an intrinsic
operator that your trying to overload while * is an intrinsic
operator that you have overloaded.   What Harald has found with the
type conversion, likely means that gfortran thinks that your generic
interface does not apply because it does not include

  multcc(v,m)
    complex, intent(in) :: v(:)
    complex, intent(in) :: m(:,:)
    ...

since your overloaded operator doesn't have  multcc, gfortran
assumes that * is the intrinsic operator and issues the correct
error.  In fact, I just add multcc to your example code and it
compiles and runs without a problem.

Note, the Fortran standard has language to ensure that an ambiguity
does not arise when overloading.

   If the operator is an intrinsic-operator(R608), the number of dummy
   arguments shall be consistent with the intrinsic uses of that operator,
   and the types, kind type parameters, or ranks of the dummy arguments
   shall differ from those required for the intrinsic operation (10.1.5).

  parent reply	other threads:[~2023-04-28  1:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  1:41 [Bug fortran/109641] New: " adelson.oliveira at gmail dot com
2023-04-27 18:04 ` [Bug fortran/109641] " anlauf at gcc dot gnu.org
2023-04-27 19:21 ` anlauf at gcc dot gnu.org
2023-04-27 20:15 ` anlauf at gcc dot gnu.org
2023-04-27 20:54 ` anlauf at gcc dot gnu.org
2023-04-28  0:34 ` adelson.oliveira at gmail dot com
2023-04-28  1:15 ` kargl at gcc dot gnu.org [this message]
2023-04-28  1:35 ` adelson.oliveira at gmail dot com
2023-04-28  1:37 ` adelson.oliveira at gmail dot com
2023-04-28  2:21 ` sgk at troutmask dot apl.washington.edu
2023-04-28 21:07 ` anlauf at gcc dot gnu.org
2023-04-29  2:20 ` adelson.oliveira at gmail dot com
2023-04-29 19:00 ` anlauf at gcc dot gnu.org
2023-04-30  2:55 ` adelson.oliveira at gmail dot com
2023-04-30 23:19 ` adelson.oliveira at gmail dot com
2023-05-01 16:31 ` anlauf at gcc dot gnu.org
2023-05-05 19:23 ` cvs-commit at gcc dot gnu.org
2023-05-18 16:54 ` cvs-commit at gcc dot gnu.org
2023-05-18 17:01 ` anlauf at gcc dot gnu.org
2023-05-19  0:41 ` adelson.oliveira at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109641-4-vsimsLIBUA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).