08-171 To: J3 From: Malcolm Cohen Subject: Interp F95/0102 Date: 2008 May 09 ---------------------------------------------------------------------- NUMBER: F95/0102 TITLE: mask-expr evaluated only once KEYWORDS: WHERE DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Is a mask-expr required to be evaluated in a WHERE such as: WHERE ( (/ .TRUE., .TRUE. /) ) A = A + 1 ELSE WHERE (MASKF()) A = MAX END WHERE where an optimizing compiler might notice that the ELSEWHERE branch will never be executed ? Page 112, line 38 says of the mask expression in ELSEWHERE statements "The mask-expression is evaluated only once." ANSWER: The above quote is from the Fortran 95 standard. In Fortran 2003 the mask expression in an ELSEWHERE is not required to be evaluated, and this is made clear by the fourth paragraph of 7.4.3.2 (at [147:7]) which, referring to a masked ELSEWHERE statement, states "The is evaluated at most once." This also applies to the mask expressions of nested WHERE construct statements; this is made clear by the last sentence of the seventh paragraph of 7.4.3.2 (at [147:16]) which also states that it is evaluated "at most once". However, this does not apply to the mask expression of the outermost WHERE construct statement, which must be evaluated exactly once; this is made clear by the last statement of the first paragraph of 7.4.3.2 (at [147:1]) which states that this mask expression is evaluated "only once". That does not guarantee invocation of functions in that expression if they are not required to determine its value. EDITS: None. SUBMITTED BY: Matthijs van Waveren HISTORY: 03-239 m165 F95/0102 Passed by J3 meeting vote 04-417r1 m170 Passed by J3 letter ballot #8 05-180 m172 Failed WG5 ballot N1617 08-171 m184 Revised answer. ----------------------------------------------------------------------