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

Optional dummy argument in specification expression

IanH
Honored Contributor II
264 Views

Fortran 200[3,8,X] permits a primary in a specification expression to be a dummy argument that is not OPTIONAL.  I don't think ifort is enforcing this, as written in the standard.

MODULE m
  IMPLICIT NONE
CONTAINS
  FUNCTION optional_fun(arg)
    INTEGER, INTENT(IN), OPTIONAL :: arg
    INTEGER :: optional_fun(pure_fun(arg))    !<-- Notional badness
    optional_fun = 1
  END FUNCTION optional_fun
  
  PURE FUNCTION pure_fun(arg)
    INTEGER, INTENT(IN), OPTIONAL :: arg
    INTEGER :: pure_fun
    IF (PRESENT(arg)) THEN
      pure_fun = arg
    ELSE
      pure_fun = 0
    END IF
  END FUNCTION pure_fun
END MODULE m

PROGRAM p
  USE m
  IMPLICIT NONE
  
  PRINT *, SIZE(optional_fun(1))
  PRINT *, SIZE(optional_fun())
END PROGRAM p


 

>ifort /check:all /warn:all /standard-semantics /stand:f2003 "2016-09-03 optional-fun.f90"
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0 Beta Build 20160517
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

ifort: NOTE: The Beta evaluation period for this product ends on 7-oct-2016 UTC.
Microsoft (R) Incremental Linker Version 14.00.24213.1
Copyright (C) Microsoft Corporation.  All rights reserved.

"-out:2016-09-03 optional-fun.exe"
-subsystem:console
"2016-09-03 optional-fun.obj"

>"2016-09-03 optional-fun.exe"
 1
 0

The effective restriction on using an optional argument as an actual argument to a pure function that has a corresponding optional dummy argument in a specification expression seems a little artificial to me, given that F2008 explicitly (F08/0095) permits references to the PRESENT intrinsic in specification expressions.

I can't think of any way of providing default values for not-present optional arguments in specification expressions :(

0 Kudos
3 Replies
Steven_L_Intel1
Employee
264 Views

Thanks.

0 Kudos
Steven_L_Intel1
Employee
264 Views

Escalated as issue DPD200414144. 

0 Kudos
Steven_L_Intel1
Employee
264 Views

Fixed for a future major release (second half of 2017).

0 Kudos
Reply