Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

GENERIC as replacement for INTERFACE overloading

jwmwalrus
New Contributor I
1,403 Views

Hi.

The following code

module mod1
    implicit none

    private
    save

    generic, public :: x => x1

contains
    subroutine x1()
    end subroutine
end module

module mod2
    use mod1

    implicit none

    private
    save

    generic, public :: x => x2
contains
    subroutine x2(v)
        integer, intent(in) :: v
    end subroutine
end module

 

fails to compile with

generic.f90(22): error #6270: This generic entity has already been assigned the PRIVATE attribute. [X]
generic, public :: x => x2
-----------------------^
compilation aborted for generic.f90 (code 1)

 

But this code compiles without issues

module mod1
    implicit none

    private
    save

    interface x
        module procedure x1
    end interface
    public x

contains
    subroutine x1()
    end subroutine
end module

module mod2
    use mod1

    implicit none

    private
    save

    interface x
        module procedure x2
    end interface
    public x

contains
    subroutine x2(v)
        integer, intent(in) :: v
    end subroutine
end module

So, is it a bug or is the compiler right at complaining?

Compiled with the following versions, with same results:

 

ifx version 2023.1.0

ifort version 2021.9.0

 

6 Replies
Steve_Lionel
Honored Contributor III
1,388 Views

This is interesting. I'll note that the GENERIC statement outside of a type declaration is a F2018 feature, which is why. when I tried it with the NAG compiler, it complained about the syntax.

I'd say that this is a compiler bug, as if you do this instead:

    generic :: x => x2
    public :: x

the compiler is happy. 

0 Kudos
jwmwalrus
New Contributor I
1,360 Views

Thanks for the reply @Steve_Lionel .

 

It's good to see that, even though you retired, you're also still around.

 

And back on the topic: there's also the minor issue of always requiring "::", even without the access-spec.

0 Kudos
Steve_Lionel
Honored Contributor III
1,320 Views

@jwmwalrus wrote:

 

And back on the topic: there's also the minor issue of always requiring "::", even without the access-spec.


That's required by the standard:

R1510 generic-stmt is GENERIC [ , access-spec ] :: generic-spec => specific-procedure-list

Note that the :: is not denoted as optional.

0 Kudos
jwmwalrus
New Contributor I
1,316 Views

Hmm... I was using this document as a guide for what's new in f2018:

http://armnlib.uqam.ca/PDF/The_New_Features_of_Fortran_2018.pdf

 

At section 5.23 the GENERIC is mentioned. So it seems the syntax there is wrong.

Thanks.

0 Kudos
Steve_Lionel
Honored Contributor III
1,295 Views

Indeed, that is an error in the document. It's a shame none of us caught it in review.

0 Kudos
Ron_Green
Moderator
1,280 Views

bug ID is CMPLRLLVM-48226


0 Kudos
Reply