http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47399

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-22 
00:06:43 UTC ---
In Fortran 2003 the constraint was:

"C1103 (R1101) An automatic object shall not appear in the specification-part
(R204) of a main program."

"C1106 (R1104) An automatic object shall not appear in the specification-part
of a module."


In Fortran 2008 the same exists - but a bit more subtle:

"C513 An automatic object shall not have the SAVE attribute."

And "5.3.16 SAVE attribute" has: "A variable, common block, or procedure
pointer declared in the scoping unit of a main program, module, or submodule
implicitly has the SAVE attribute, which may be conrmed by explicit
specification."


Except for the less-helpful wording in case of character lengths ("must have
constant character length in this context" [which context?]) the checks
exist.For strings it seems to work, for arrays the call to
is_non_constant_shape_array in resolve_fl_variable does not seem to work.


The reason is: resolve_index_expr checks for:

  if (gfc_specification_expr (e) == FAILURE)
    return FAILURE;

The problem is: We do have a specification expression, but not an
initialization expression.

We run -- again -- into the following issue in gfc_is_constant_expr:

      /* Specification functions are constant.  */
      /* F95, 7.1.6.2; F2003, 7.1.7  */
      if (sym
          && sym->attr.function
          && sym->attr.pure
          && !sym->attr.intrinsic
          && !sym->attr.recursive
          && sym->attr.proc != PROC_INTERNAL
          && sym->attr.proc != PROC_ST_FUNCTION
          && sym->attr.proc != PROC_UNKNOWN
          && sym->formal == NULL)
        return 1;

There are more bugs of this kind.

Fortran 2008 defines:

"7.1.11 Specication expression"
* "specification expression is an expression with limitations that make it
suitable for use in specications such as length type parameters (C404) and
array bounds (R517, R518). [...]"
* "A restricted expression is an expression in which each operation is
intrinsic or dened by a specication function and [...]"

"7.1.12 Constant expression"
"A constant expression is an expression with limitations that make it suitable
for use as a kind type parameter, initializer, or named constant. [...]"

Fortran 2003 uses:

"7.1.6 Specification expression"
* "A specification expression is an expression with limitations that make it
suitable for use in specifications such as length type parameters (C501) and
array bounds (R512, R513)."
* "A restricted expression is an expression in which each operation is
intrinsic and [...]"
"7.1.7 Initialization expression
An initialization expression is an expression with limitations that make it
suitable for use as a kind type parameter, initializer, or named constant."

Fortran 95 used the terms:

"7.1.6.2 Specification expression"
"A specification expression is an expression with limitations that make it
suitable for use in specifications such as character lengths (R510) and array
bounds (R515, R516). A constant specification expression is a specification
expression that is also a constant expression."
"A restricted expression is an expression in which each operation is intrinsic
and ..."

"7.1.6.1 Constant expression"
"A constant expression is an expression in which each operation is intrinsic
and ..."
"An initialization expression is a constant expression in which the
exponentiation operation is permitted only with an integer power, and ..."


Thus:
      /* Specification functions are constant.  */
      /* F95, 7.1.6.2; F2003, 7.1.7  */

Is nonsense. In the Fortran 2008 sense constant means that it can be simplified
at compile time to a constant (a number, a string literal, ...). In the Fortran
2003 sense, that's an initialization expression ("constant expression" does not
exist). While also in the Fortran 95 sense a "constant expression" is something
where a number can be returned. That's given in 7.1.6.2 while 7.1.6.2 is about
"specification expressions", "constant specification expressions" and
"restricted expressions".

 * * *

Thus, the proper change is to simply delete that invalid part. The only catch
is: That will cause problems with sections of gfortran which call
gfc_constant_expr but do not want to have a constant expression but a
specification expression!

There was some PR before: Namely PR 44962, cf.
http://gcc.gnu.org/ml/fortran/2010-07/msg00285.html

Reply via email to