From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45656 invoked by alias); 7 Sep 2018 17:20:58 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 45641 invoked by uid 89); 7 Sep 2018 17:20:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=H*i:sk:CAJ3Baz, type-bound, H*r:sk:m62-v6s, typebound X-HELO: mail-yw1-f68.google.com Received: from mail-yw1-f68.google.com (HELO mail-yw1-f68.google.com) (209.85.161.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Sep 2018 17:20:56 +0000 Received: by mail-yw1-f68.google.com with SMTP id m62-v6so5656583ywd.6 for ; Fri, 07 Sep 2018 10:20:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Janus Weil Date: Fri, 07 Sep 2018 17:20:00 -0000 Message-ID: Subject: Re: Assignment interfaces with allocatable polymorphic variables in gfortran 5.5.0 & 8.1.0. To: ethanbeyak@gmail.com Cc: gfortran Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00080.txt.bz2 Am Fr., 7. Sep. 2018 um 16:36 Uhr schrieb Ethan Beyak : > Thank you very much for your response. I didn't realize you could put an = 'assignment (=3D)' in a public statement. This'll solve my problem perfectl= y! > > As a follow-up, let's say I did have multiple 'interface assignment (=3D)= ' blocks in this module. Would the 'public assignment (=3D)' statement then= make all of assignments public then? I think so. > Is there any way I could apply the public attribute to the interface bloc= k directly, or am I limited to public statements for affecting the accessib= ility of interface blocks? I'm afraid there is no syntax for specifying accessibility in the INTERFACE statement directly. I have also been missing such a feature occasionally. Another thing you could do is to use a type-bound assignment operator, like= so: type vector real :: x, y, z contains procedure :: foo generic :: assignment(=3D) =3D> foo end type vector However, this approach seems to conflict with the allocatable argument that you are using in 'foo'. At least that's what gfortran says: 19 | procedure :: foo | 1 Error: Passed-object dummy argument of =E2=80=98foo=E2=80=99 at (1) must no= t be ALLOCATABLE > And a brief convention question: is it standard to omit whitespace betwee= n 'assignment' and '(=3D)' when writing Fortran, or is there no general con= sensus? You can, but you don't have to. It's a question of personal preference. I don't think there is any 'general consensus'. Cheers, Janus > On Fri, Sep 7, 2018 at 5:56 AM Janus Weil wrote: >> >> Hi Ethan, >> >> > However, on version 5.5, I get the following errors: >> > >> > OUTPUT 2 >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D >> > $ gfortran --version >> > GNU Fortran (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 >> > >> > $ gfortran baz_module.f90 test_public_assignment.f90 -o test.out >> > test_public_assignment.f90:13:0: >> > >> > wrk =3D e ! invoking foo >> > 1 >> > Error: Assignment to an allocatable polymorphic variable at (1) is not= yet >> > supported >> > test_public_assignment.f90:19:0: >> >> Note that gfortran version 7 can also compile the program in its >> original form (so you don't necessarily need version 8), but >> unfortunately earlier versions fail. >> >> >> > Now I did find some workaround by setting the default accessibility of= the >> > module to be public and explicitly declaring the complement of the set= of >> > procedures and variables that I wanted to be private. I'm not sure what >> > gfortran 5.5.0 is doing to be honest, but the definition of the assign= ment >> > can be used in the calling program. Commenting out lines 5,6 and comme= nting >> > in lines 8,9 in baz_module.f90 gave me the following output on gfortran >> > 5.5.0 >> > >> > OUTPUT 3 >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D >> > Compiler version: GCC version 5.5.0 20171010 >> > Compiler options: -mtune=3Dgeneric -march=3Dx86-64 >> > d: 4.00000000 2.00000000 1.00000000 >> > e: 8.00000000 6.00000000 4.00000000 >> > f: 32.0000000 18.0000000 8.00000000 >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D >> > >> > So I have two questions for the gfortran community: 1) do you know why >> > inverting the module accessibility causes these assignments to work in >> > gfortran 5.5.0? It seems as if the assignment interface was made public >> > somehow, but I'm not certain. >> >> Exactly, the "public" statement makes everything in the module public >> by default. The assignment operator is private otherwise. >> >> >> > 2) can you think of any *clean* solutions to >> > this problem? I'd love backward compatibility while not going against = the >> > recommended standard of private default accessibility. >> >> A more reasonable approach might be to not make everything public, but >> just the assignment interface: >> >> public assignment(=3D) >> >> HTH, >> Janus