- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[edited to add the empty parens on functions to be F2003 compliant -- thx Abhi]
Visual Fortran 11.1.065 [IA-32] compiles the invalid code below without error. If you combine the two modules into one you do get a reasonable error (error #8280: An overriding binding and its corresponding overridden binding must both be either subroutines or functions with the same result type, kind, and shape. [NAME]) Note in the example below the length of the return type varies based on an internal parameter so the polymorphic function doesn't have a consistent length type parameter. I've seen crashes with this sort of code. Compiles OK (but may crash at runtime)
[fortran]module M10 type :: B contains procedure, nopass :: name => B_name end type B contains function B_name() result character(len=*), parameter :: c = 'short_name' character(len=len(c)) :: r r = c end function B_name end module M10 module M11 use M10 type, extends(B) :: D contains procedure, nopass :: name => D_name end type contains function D_name() result character(len=*), parameter :: c = 'longer_name_is_longer' character(len=len(c)) :: r r = c !may crash here end function D_name end module M11[/fortran]Compiles with Error 8280 described above:
[fortran]module M10 type :: B contains procedure, nopass :: name => B_name end type B type, extends(B) :: D contains procedure, nopass :: name => D_name end type contains function B_name() result character(len=*), parameter :: c = 'short_name' character(len=len(c)) :: r r = c end function B_name function D_name() result character(len=*), parameter :: c = 'longer_name_is_longer' character(len=len(c)) :: r r = c end function D_name end module M10[/fortran]
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[edited to add the empty parens to be F2003 compliant -- thx Abhi]
Forgot to mention that if you change the result type to a pointer with a (len=:) type parameter then the code below compiles without error as you would expect (because the type parameters are consistent); note the added saved variable because pointers can't target parameters.Compiles OK:
[fortran]module M12 type :: B contains procedure, nopass :: name => B_name end type B type, extends(B) :: D contains procedure, nopass :: name => D_name end type contains function B_name() result character(len=*), parameter :: c = 'short_name' character(len=len(c)), save, target :: v = c character(len=:), pointer :: r r => v end function B_name function D_name() result character(len=*), parameter :: c = 'longer_name_is_longer' character(len=len(c)), save, target :: v = c character(len=:), pointer :: r r => v end function D_name end module M12[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[Based on the standard wording below I think the merged module behavior is correct and bug pointed out in this thread is that the compiler is not rejecting the code when split into two modules]
From:6 4.5.6.2 Type-bound procedure overriding...
(7) Either both shall be subroutines or both shall be functions having the same result characteristics (12.2.2).
12.2.2 Characteristics of function results
The characteristics of a function result are its type, type parameters (if any), rank, whether it is polymorphic, whether it is allocatable, whether it is a pointer, and whether it is a procedure pointer. If afunction result is an array that is not allocatable or a pointer, its shape is a characteristic. If a typeparameter of a function result or a bound of a function result array is not an initialization expression, theexact dependence on the entities in the expression is a characteristic. If type parameters of a functionresult are deferred, which parameters are deferred is a characteristic. If the length of a character functionresult is assumed, this is a characteristic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Joseph
Just an observation; most likely you already know this:- changing function to subroutine traps it.
Abhi
p.s. A very minor point: As per standard, Function must have () after the function name. i.e. Function B_name() result, the paranthesis should not be omitted. IVF correctly gives a warning with /stand:f03.
Just an observation; most likely you already know this:- changing function to subroutine traps it.
Abhi
p.s. A very minor point: As per standard, Function must have () after the function name. i.e. Function B_name() result, the paranthesis should not be omitted. IVF correctly gives a warning with /stand:f03.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot for your point! I have been running with /stand:f03 turned off because of conflicts I found in release 5 of 11.1 that kept me from using some f2003 features. I need to start running with it turned on by default and turning it off for modules that break with it (if they do.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have escalated this as issue DPD200157909.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has been fixed for a release later this year.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page