This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/49331] Accepts invalid specification expressions
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 9 Jun 2011 08:17:34 +0000
- Subject: [Bug fortran/49331] Accepts invalid specification expressions
- Auto-submitted: auto-generated
- References: <bug-49331-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49331
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-06-09 08:17:30 UTC ---
The examples of the IR 11-101 do not work for me as the examples do not involve
constant expressions when defining the kind value (unless I am seriously
mistaken).
Better/shorter example:
module m
type t
integer :: i
end type t
interface LEN
module procedure my_len
end interface LEN
contains
function one(x)
type(t),intent(in) :: x
character(len=LEN(x)) :: one
one = ''
end function one
integer pure function my_len(x)
type(t), intent(in) :: x
my_len = x%i
end function my_len
end module m
The suggested wording for specification expressions - but also for constant
expressions (cf. 11-101 for the latter) is:
Replace F08/7.1.11p9 [10-007:151:13-15] by
"A generic entity referenced in a specification expression in the
<specification-part> of a scoping unit shall have no specific
procedures defined in that scoping unit, or its host scoping unit,
subsequent to the specification expression."
Thus, the example would also be invalid if instead of
LEN(x) ! Calls specific which is later defined
one had used
LEN(x%i) ! Call intrinsic LEN
(and, indeed, crayftn also rejects that example).
I wonder whether there is a better method than:
if (generic_sym->ns == current_ns->parent && !generic_sym->attr.use_assoc)
{
LOOP through all specific_sym:
if (current_ns->parent == specific_sym->ns->parent)
&& LOCATION_LINE (current_loc->location)
< LOCATION_LINE (specific_sym->declared_at->location))
gfc_error (...)
}
(In case the specific function is referenced for a specific function which is
an internal function, gfortran already prints: "Error: Generic function 'len'
at (1) is not consistent with a specific intrinsic interface".)
* * *
Example for a constant expression:
module m
type t
integer :: i
end type t
interface LEN
module procedure my_len
end interface LEN
contains
function one(x)
type(t),intent(in) :: x
character(kind=kind(LEN())) :: one
one = ''
end function one
integer pure function my_len()
my_len = 1
end function my_len
end module m