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
accessibility.

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
fix.

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



Relevant Pages

  • Re: Private return type of public functions
    ... itself, but the module "useType". ... The compiler already aborts during ... In the Fortran 95 draft at my disposal I've found a constraint ... result of a type that has PRIVATE accessibility shall have PRIVATE ...
    (comp.lang.fortran)
  • Re: Private return type of public functions
    ... itself, but the module "useType". ... The compiler already aborts during ... the derived type "myType" is private. ...
    (comp.lang.fortran)
  • Re: Typ-System, Typ-Arithmetik
    ... Code, der mit Deinem Ansatz so funktionieren wuerde, sondern eigentlich ... Java-Generics sind auch nur dem Compiler bekannt. ... wo dieser Constraint aktiv ist. ... wahr ist (Ob der linke Ausdruck den ...
    (de.comp.lang.java)
  • Re: Why does compiler only look at public methods of superclasses of...?
    ... Compiler enumerates all methods in class A and all public methods ... in the superclasses of A to find methods named x ... if method is declared final, static or private then compiler knows ... override a protected method. ...
    (comp.lang.java.programmer)
  • Re: Linux X demo
    ... when the source code obviously violates a required ... Yes, it's a warning, not an error message, but the standard makes no ... constraint invokes undefined behavior; the standard says so ... implementation's documentation makes a promise that the compiler fails ...
    (comp.lang.c)