- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A feature request - I appreciate there's no constraint, but 12.0.2 and earlier will complain if an overriding procedure doesn't have a argument list that appropriately matches the overridden procedure, which is nice. Could we please have that check extended to function results as well?
[fortran]MODULE A_mod IMPLICIT NONE PRIVATE TYPE, PUBLIC :: A_type CONTAINS PROCEDURE, NOPASS :: Sub => a_Sub PROCEDURE, NOPASS :: Fun => a_Fun END TYPE A_type CONTAINS SUBROUTINE a_Sub(i, r) INTEGER, INTENT(IN) :: i INTEGER, INTENT(OUT) :: r !**** r = i + 1 END SUBROUTINE a_Sub FUNCTION a_Fun(i) RESULT INTEGER, INTENT(IN) :: i INTEGER :: r !**** r = i + 1 END FUNCTION a_Fun END MODULE A_mod MODULE B_mod USE A_mod IMPLICIT NONE PRIVATE TYPE, EXTENDS(A_type), PUBLIC :: B_type CONTAINS PROCEDURE, NOPASS :: Sub => b_Sub PROCEDURE, NOPASS :: Fun => b_Fun END TYPE B_type CONTAINS SUBROUTINE b_Sub(i, r) INTEGER, INTENT(IN) :: i INTEGER, INTENT(OUT) :: r !REAL, INTENT(OUT) :: r ! This would cause error #8383 !**** r = i + 2.0 END SUBROUTINE b_Sub FUNCTION b_Fun(i) RESULT INTEGER, INTENT(IN) :: i REAL :: r ! Oops! Silly programmer... !**** r = i + 2.0 END FUNCTION b_Fun END MODULE B_mod PROGRAM fun_intf_matching_not USE A_mod USE B_mod IMPLICIT NONE TYPE(B_type) :: not_poly_var CLASS(A_type), ALLOCATABLE :: poly_var !**** PRINT *, not_poly_var%Fun(1) ! "3.0" - all good - my maths is ok. ALLOCATE(B_type :: poly_var) PRINT *, poly_var%Fun(1) ! "1" - uh oh... back to school for me!? END PROGRAM fun_intf_matching_not [/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the feature request. I have submitted it to engineering with tracking number: DPD200165615. Not sure you are familiar with our Static Security Analysis available by purchasing Intel Parallel Studio XE? It uses the Inspector product to find coding errors like this (although I have not tested it on this particular error). More info here:
http://software.intel.com/en-us/articles/intel-parallel-studio-xe/
------
Wendy
Attaching or including files in a post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran]MODULE BarParentMod IMPLICIT NONE PRIVATE TYPE, PUBLIC :: Foo END TYPE Foo TYPE, PUBLIC, ABSTRACT :: BarParent CONTAINS PROCEDURE(intf_without_allocatable_arg), DEFERRED :: Proc END TYPE BarParent ABSTRACT INTERFACE SUBROUTINE intf_without_allocatable_arg(obj, arg, dt) IMPORT :: BarParent, Foo IMPLICIT NONE CLASS(BarParent), INTENT(IN) :: obj REAL, INTENT(OUT) :: arg ! Oops! Should be allocatable. CLASS(Foo), INTENT(OUT) :: dt END SUBROUTINE intf_without_allocatable_arg END INTERFACE END MODULE BarParentMod MODULE BarMod USE BarParentMod IMPLICIT NONE PRIVATE TYPE, PUBLIC, EXTENDS(BarParent) :: Bar CONTAINS PROCEDURE :: Proc => proc_with_allocatable_arg END TYPE Bar CONTAINS SUBROUTINE proc_with_allocatable_arg(obj, arg, dt) CLASS(Bar), INTENT(IN) :: obj REAL, INTENT(OUT), ALLOCATABLE :: arg TYPE(Foo), INTENT(OUT) :: dt ! Oops! - I'm not very classy. !**** ALLOCATE(arg) arg = 1.0 END SUBROUTINE proc_with_allocatable_arg END MODULE BarMod PROGRAM NoCheckOfAllocatableOrPolymorphic USE BarParentMod USE BarMod IMPLICIT NONE CLASS(BarParent), ALLOCATABLE :: obj REAL :: arg TYPE(Foo) :: dt !**** ALLOCATE(Bar:: obj) CALL obj%Proc(arg, dt) END PROGRAM NoCheckOfAllocatableOrPolymorphic [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
------
Wendy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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