Re: Private return type of public functions

Reinhold Bader <Bader@xxxxxx> wrote:

Bálint Aradi schrieb:


You're completely right. The problem is, however, not the program
itself, but the module "useType". The compiler already aborts during
the compilation of this module. At that point it does not know
anything about the way it will be used later. In the module "useType"
itself, the derived type "myType" is private. The question is then, if
the compiler behaves correctly, when refusing to compile the useType
module in F95 standard mode with the following error message:
In the Fortran 95 draft at my disposal I've found (section 5.2.3) a constraint
which indeed appears to forbid this:

Constraint: A module procedure that has a dummy argument or function
result of a type that has PRIVATE accessibility shall have PRIVATE
accessibility and shall not have a generic identifier that has PUBLIC

I do not know whether later corrections to the standard have been devised
to limit this to the case of the type definition itself being private.

(Fortran 2003 is by necessity more liberal here, since it is possible to have
public entities of private type).


Your earlier answer was correct. The type is not actually private, for
just the reason you stated, and thus the above constraint does not
apply. There was an interp on exactly this question, clarifying the
above point. I'm somewhat impressed that you got the answer so correct
without knowing about the interp, as it was a pretty subtle point that
took quite a bit of time for J3 to resolve. Your original answer,
though, was spot on in describing the resolution.

F2003 fixed this confusing constraint by removing it. It was a misguided
constraint in the first place, achieving nothing useful.

I believe I recall Andy fixing g95 to get this right, though it is
possible that I misrecall or that he didn't catch every case. It also
seems possible that the OP might have a version of g95 from before the

Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain