To: J3 10-145 From: Bill Long Subject: Interp Request: Generic resolution with pointer dummy args Date: 2010 March 27 References: WG5/N1814.pdf Note: All page, clause, and paragraph references are to WG5/N1814. Discussion: ----------- In f08 at [286:12.4.3.4.5p3] we allow (as a new feature) a dummy argument with the ALLOCATABLE attribute to be distinguishable from a dummy argument with the POINTER attribute. Thus, I would conclude that this generic interface is OK: interface sub subroutine suba (a) real,allocatable :: a(:) end subroutine suba subroutine subp (a) real,pointer,intent(in) :: a(:) end subroutine subp end interface sub This extension made perfect sense in the f03 context of pointer dummy shall correspond to pointer actual. However, at [296:12.5.2.7p2] we have another new feature that allows a pointer dummy to correspond to a non-pointer actual. So, assuming the interface for sub above, how is the following resolved: real,allocatable,target :: actual(:) allocate(actual(100)) call sub (actual) Either of the specific interfaces appears to be viable as a callee. Question: --------- Is there a fundamental contradiction in N1814, as exposed by the example in the Discussion? Answer: ------- Yes. The feature (12.4.3.4p3, below referred to as GEN) of allowing a dummy argument with the ALLOCATABLE attribute to be distinguished from a dummy argument with the POINTER attribute in a generic interface conflicts with the feature (12.5.2.7p2, below referred to as PTR) of allowing an actual argument with the ALLOCATABLE attribute to correspond to a dummy with the POINTER attribute (and INTENT(IN) attribute). Resolution Alternatives: ------------------------ 1) Modify feature GEN to restrict the dummy argument with the POINTER attribute to not have the INTENT(IN) attribute for it to be distinguishable from a dummy with the ALLOCATABLE attribute. This would make the generic interface above disallowed. 2) Modify feature PTR by adding "nonallocatable" before "target" in 12.5.2.7p2. By disallowing an allocatable actual to correspond to the pointer dummy, the second section of example code above is disallowed. 3) Remove feature GEN from the standard. This makes the generic interface disallowed. 4) Remove feature PTR from the standard. This makes the call statement in the example disallowed. 5) Introduce a new rule that establishes a priority favoring an exact match in the case of more than one specific interface is allowed for a reference to the generic. In this case, the specific suba would be selected because the actual and dummy arguments are both allocatable. Resolution: ----------- Alternative 1 preserves the most functionality of the two features while also resolving the contradiction, and is hence favored. Edits for this alternative are provided. Edits: ------ In [286:12.4.3.4.5p3, line 4] after the current text: "one has the ALLOCATABLE attribute and the other has the POINTER attribute" add "and does not have the INTENT(IN) attribute"