public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49331] New: Accepts invalid specification expressions
@ 2011-06-08 21:09 burnus at gcc dot gnu.org
  2011-06-09  8:17 ` [Bug fortran/49331] " burnus at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-06-08 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Accepts invalid specification expressions
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


gfortran currently compiles http://www.fortran.com/iso_varying_string.f95 with
-std=f2003 without any error.

Expected: gfortran rejects the program with an error messages.


Crayftn correctly rejects the program with:

      character(LEN=len(string))       :: char_string
                    ^
ftn-355 crayftn: ERROR CHAR_AUTO, File = iso_varying_string.f90, Line =
861, Column = 19
    Generic interface "LEN" is referenced in a declarative expression in
a [sub]module.  Specific "LEN_" must be completely specified prior to
being referenced.


The function being use is the innocently looking:

    pure function char_auto (string) result (char_string)
      type(varying_string), intent(in) :: string
      character(LEN=len(string))       :: char_string

However, the specific function to which then LEN() resolves is not the
intrinsic LEN, but the specific function LEN_, which is defined in the same
module - but (crucially!) later than the function char_auto, which uses it.
That's invalid!


For a shorter example, see interpretation request J3/11-101, F08/0050, which
passed already J3 and will be voted on soon by WG5. Cf.
http://j3-fortran.org/doc/year/11/11-101r1.txt
(Note: If the file is edited, the revision number is incremented, please
remember to check whether there is, e.g., a 11-101r2.txt.)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/49331] Accepts invalid specification expressions
  2011-06-08 21:09 [Bug fortran/49331] New: Accepts invalid specification expressions burnus at gcc dot gnu.org
@ 2011-06-09  8:17 ` burnus at gcc dot gnu.org
  2014-03-22 19:52 ` dominiq at lps dot ens.fr
  2021-12-18  2:41 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-06-09  8:17 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/49331] Accepts invalid specification expressions
  2011-06-08 21:09 [Bug fortran/49331] New: Accepts invalid specification expressions burnus at gcc dot gnu.org
  2011-06-09  8:17 ` [Bug fortran/49331] " burnus at gcc dot gnu.org
@ 2014-03-22 19:52 ` dominiq at lps dot ens.fr
  2021-12-18  2:41 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-03-22 19:52 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-03-22
     Ever confirmed|0                           |1

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
For the second test in comment 1, I get the following errors (r208766)

pr49331_1.f90:11.30:

    character(kind=kind(LEN())) :: one
                              1
Error: Kind 0 is not supported for CHARACTER at (1)
pr49331_1.f90:12.10:

    one = ''
          1
Error: Can't convert CHARACTER(1) to REAL(4) at (1)

but nor error for iso_varying_string.f95 compiled with -std=f2003.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/49331] Accepts invalid specification expressions
  2011-06-08 21:09 [Bug fortran/49331] New: Accepts invalid specification expressions burnus at gcc dot gnu.org
  2011-06-09  8:17 ` [Bug fortran/49331] " burnus at gcc dot gnu.org
  2014-03-22 19:52 ` dominiq at lps dot ens.fr
@ 2021-12-18  2:41 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-18  2:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49331

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #0)
> gfortran currently compiles http://www.fortran.com/iso_varying_string.f95
> with -std=f2003 without any error.

File does not exist any more :(.

(In reply to Dominique d'Humieres from comment #2)
> For the second test in comment 1, I get the following errors (r208766)
Same behavior with the trunk.
Also ifort has the same behavior as GCC including accepting the first test in
comment #1.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-18  2:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-08 21:09 [Bug fortran/49331] New: Accepts invalid specification expressions burnus at gcc dot gnu.org
2011-06-09  8:17 ` [Bug fortran/49331] " burnus at gcc dot gnu.org
2014-03-22 19:52 ` dominiq at lps dot ens.fr
2021-12-18  2:41 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).