To: J3 J3/20-127 From: Malcolm Cohen Subject: Public namelist and private variable Date: 2020-February-27 ---------------------------------------------------------------------- NUMBER: F18/018 TITLE: Public namelist and private variable KEYWORDS: NAMELIST PUBLIC PRIVATE DEFECT TYPE: Clarification STATUS: J3 consideration in progress QUESTION: Consider Module m1 Real,Public :: x End Module Module m2 Use m1 Private x Namelist/nml/x End Module On the face of it, module M2 appears to violate C8105 (R868) A namelist-group-object shall not have the PRIVATE attribute if the namelist-group-name has the PUBLIC attribute. as the local X indeed has the PRIVATE attribute. On the other hand, it is just a local name for the remote X which is PUBLIC, which raises doubts. Comment: This seems to be a very old constraint dating back to when the standard was much more restrictive about such things. It is not clear why this should be disallowed. Even if X were a local variable of M2, it is not clear what purpose this constraint serves. A quick compiler survey revealed that most but not all compilers think that it is where the variable is defined that matters, i.e. many accept the example code. Q1. Should PRIVATE local variables really be prohibited from a PUBLIC namelist? If the answer to Q1 is yes, Q2. Is it PRIVATE on the local name that matters, or PRIVATE on the variable where it is defined? COMMENT: A NAMELIST statement can contain several namelist-group-names, so it is also somewhat ambiguous as to which namelist-group-objects this constraint applies to. ANSWER: A1. Yes. Although this restriction appears to serve little purpose, it is a deliberate restriction (which could be lifted in a future standard). A2. It is whether the variable is defined to have the PRIVATE attribute that matters, not the local name. ALTERNATIVE A2. It is whether the local name has the PRIVATE attribute that matters, not where the variable is defined. END ALTERNATIVE An edit is provided. EDIT to 18-007r1: [119:8-9] 8.9 NAMELIST statement, C8105, After "PRIVATE attribute" insert "in the scope where the variable is defined" and change "the namelist-group-name" to "its namelist-group-name", making the whole constraint read "C8105 (R868) A namelist-group-object shall not have the PRIVATE attribute in the scope where the variable is defined if its namelist-group-name has the PUBLIC attribute." ALTERNATIVE [119:8-9] 8.9 NAMELIST statement, C8105, After "PRIVATE attribute" insert "in the local scope", and change "the namelist-group-name" to "its namelist-group-name", making the whole constraint read "C8105 (R868) A namelist-group-object shall not have the PRIVATE attribute in the local scope if its namelist-group-name has the PUBLIC attribute." END ALTERNATIVE {COMMENT TO J3: The constraint should probably be re-wordsmithed to be more concise and easier to read, perhaps by beginning "If a namelist-group-name has the PUBLIC attribute..." but this wordsmithing can be considered at a later date.} SUBMITTED BY: Malcolm Cohen HISTORY: 20-nnn m221 F18/018 Submitted ----------------------------------------------------------------------