12-106r1 To: J3 From: Malcolm Cohen Subject: Interpretation concerning constant expressions and pointers Date: 2012 February 13 ---------------------------------------------------------------------- NUMBER: F08/0066 TITLE: Are certain expressions with pointer initialization constant? KEYWORDS: constant, pointer initialization DEFECT TYPE: Erratum STATUS: Under J3 consideration QUESTION: Given type :: T character(len=:), pointer :: P end type T character(len=10), target, save :: V = 'Value of V' (1) Is the expression T(V) a constant expression? If so, consider the additional statement TYPE(T),PARAMETER :: Z = T(V) (2) Is the expression TRANSFER(SQRT(TRANSFER(Z,R)),Z) a constant expression? (3) Is the expression Z%P a constant expression? (4) Is the assignment Z%P = 'NEW VALUE' a valid assignment? ANSWER: (1) Yes. (2) An expression involving TRANSFER of an initialization target was not intended to be classified as a constant expression. An edit is provided to correct this. (3) Except in pointer association context, no (see 6.4.2p5). (4) Yes. In this context, Z%P is not a subobject of Z. EDITS to 10-007r1: [152:4] 7.1.12 "Constant expression", p1, item (6), After "THIS_IMAGE" insert ", TRANSFER". {Exclude the general case of TRANSFER from constant expressions.} [152:7+] After item (7) "... NULL ...", insert new item "(7a) A reference to the intrinsic function TRANSFER where each argument is a constant expression and the SOURCE argument does not have an ultimate pointer component whose value was given by an initialization target." {Exclude the problematic case without introducing an incompatibility with Fortran 95.} SUBMITTED BY: Van Snyder HISTORY: 12-106 m197 F08/0066 submitted 12-106r1 m197 Revised answer ----------------------------------------------------------------------