Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

Revisited: interaction between type constructor of base type and derived type definition

tplaakso
Beginner
714 Views
Hi,

Referring to the thread:
http://software.intel.com/en-us/forums/showthread.php?t=78685&o=a&s=lr

12.1 Update 7 seems to have solved the problem in that particular code example, but it seems to me that the fix only works within a single module. I think the following code should compile as well:
[bash]module test_1
  type base
  end type base
  interface base
     module procedure con_1
  end interface base
contains
  type(base) function con_1()
  end function con_1
end module test_1

module test_2
  use test_1
  type, extends(base) :: der
  end type der
  interface der
     module procedure con_2
  end interface der
contains
  type(der) function con_2(x)
    type(base) :: x
  end function con_2
end module test_2
[/bash]
However, I get:
[bash]ifort -free intel_typedef_bug.f 
intel_typedef_bug.f(8): warning #6178: The return value of this FUNCTION has not been defined.   [CON_1]
  type(base) function con_1()
----------------------^
intel_typedef_bug.f(21): error #6463: This is not a derived type name.   [BASE]
    type(base) :: x
---------^
intel_typedef_bug.f(20): warning #6178: The return value of this FUNCTION has not been defined.   [CON_2]
  type(der) function con_2(x)
---------------------^
compilation aborted for intel_typedef_bug.f (code 1)
[/bash]
I think the error #6463 should not be there, or am I missing something?

regards,
Teemu Laakso
0 Kudos
4 Replies
Ron_Green
Moderator
714 Views
Teemu,
Our Fortran Standards comittee members are in New England and offline due to that power outage in that region. We'll have to review this once power is restored to our offices there.
I don't know what the compiler is complaining about here. However, gfortran is not at all happy with this syntax:
$ gfortran --version
GNU Fortran (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6)
Copyright (C) 2010 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
[rwgreen@nmicl-lab3 ~]$ vi gftest.f90
[rwgreen@nmicl-lab3 ~]$ gfortran -c gftest.f90
gftest.f90:4.16:
interface base
1
Error: DERIVED attribute of 'base' conflicts with PROCEDURE attribute at (1)
gftest.f90:5.22:
module procedure con_1
1
Error: MODULE PROCEDURE at (1) must be in a generic module interface
gftest.f90:6.5:
end interface base
1
Error: Expecting END MODULE statement at (1)
gftest.f90:8.2:
type(base) function con_1()
1
Error: The type for function 'con_1' at (1) is not accessible
gftest.f90:13.12:
use test_1
1
$ gfortran --versionGNU Fortran (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6)Copyright (C) 2010 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.You may redistribute copies of GNU Fortranunder the terms of the GNU General Public License.For more information about these matters, see the file named COPYING
[rwgreen@nmicl-lab3 ~]$ vi gftest.f90[rwgreen@nmicl-lab3 ~]$ gfortran -c gftest.f90gftest.f90:4.16:
interface base 1Error: DERIVED attribute of 'base' conflicts with PROCEDURE attribute at (1)gftest.f90:5.22:
module procedure con_1 1Error: MODULE PROCEDURE at (1) must be in a generic module interfacegftest.f90:6.5:
end interface base 1Error: Expecting END MODULE statement at (1)gftest.f90:8.2:
type(base) function con_1() 1Error: The type for function 'con_1' at (1) is not accessiblegftest.f90:13.12:
use test_1 1
0 Kudos
tplaakso
Beginner
714 Views
OK, thanks for trying out gfortran. It seems that gfortran is even more confused about giving the same name for a type and its constructor.

Just to clarify, the following code goes through the latest ifort without the error #6463:
[bash]module test
  type base
  end type base
  interface base
     module procedure con_1
  end interface base
  type, extends(base) :: der
  end type der
  interface der
     module procedure con_2
  end interface der
contains
  type(base) function con_1()
  end function con_1
  type(der) function con_2(x)
    type(base) :: x
  end function con_2
end module test
[/bash]
The only difference being that all the data structures are now in a single module.

Teemu
0 Kudos
Steven_L_Intel1
Employee
714 Views
I think this should work and will let the developers know. Issue ID is DPD200175681.
0 Kudos
Steven_L_Intel1
Employee
714 Views
I expect this problem to be corrected in Update 9.
0 Kudos
Reply