Re: Extending types and ambiguous interfaces
- From: Tobias Burnus <burnus@xxxxxxxx>
- Date: Wed, 27 Apr 2011 03:38:17 -0700 (PDT)
On Apr 27, 8:53 am, Arjen Markus <arjen.markus...@xxxxxxxxx> wrote:
I have a type point2d and an extended type point3d. For both I want to
use a function add_vector or an overloaded operation +. This way
I hope my program will be able to transparently use either point2d or
point3d variables and remain completely the same (at least code-wise).
With these signatures and a generic interface I get a message that the
interface is ambiguous.
My feeling is that the program is valid (ignoring the assignment
issue, ifort 12 pointed out). However, I cannot really pinpoint it in
the standard.
In the section "12.5.5.2 Resolving procedure references to names
established to be generic" (F2008), one finds:
"If the reference is consistent with a nonelemental reference to one
of the specific interfaces of a generic interface that has that name
and either is defined in the scoping unit in which the reference
appears or is made accessible by a USE statement in the scoping unit,
the reference is to the specific procedure in the interface block that
provides that interface. The rules in 12.4.3.4.5 ensure that there can
be at most one such specific procedure."
Especially the last two sentences imply that the two procedures are
ambiguous as either provides an interface for any variable with a
declared type of "class(point3d)".
"A dummy argument is type, kind, and rank compatible, or TKR
compatible, with another dummy argument if the first is type
compatible with the second, the kind type parameters of the first have
the same values as the corresponding kind type parameters of the
second, and both have the same rank." (12.4.3.4.5 Restrictions on
generic declarations, F2008)
Here, I am not sure: both functions have different declared types, but
while passing a CLASS(point3d) to CLASS(point2d) is valid, the reverse
isn't. ("A polymorphic entity that is not an unlimited polymorphic
entity is type compatible with entities of the same declared type or
any of its extensions.", cf. "4.3.1.3 CLASS".)
And (12.4.3.4.5 Restrictions on generic declarations):
"Two dummy arguments are distinguishable if [...] they are both data
objects or known to be functions, and neither is TKR compatible with
the other" [...]
C1212 Within the scope of a generic operator, if two procedures with
that identier have the same number of arguments, one shall have a
dummy argument that corresponds by position in the argument list to a
dummy argument of the other that is distinguishable from it."
I probably should have a closer look at the "neither" and "one shall"
to understand whether
"A compatible to B AND B compatible to A"
or
"A compatible to B OR B compatible to A"
is meant.
Tobias
.
- Follow-Ups:
- Re: Extending types and ambiguous interfaces
- From: Arjen Markus
- Re: Extending types and ambiguous interfaces
- References:
- Extending types and ambiguous interfaces
- From: Arjen Markus
- Extending types and ambiguous interfaces
- Prev by Date: Re: Extending types and ambiguous interfaces
- Next by Date: Re: Is passing via rank-1 assumed-size array legal?
- Previous by thread: Re: Extending types and ambiguous interfaces
- Next by thread: Re: Extending types and ambiguous interfaces
- Index(es):
Relevant Pages
|