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

            Bug ID: 92805
           Summary: gfortran: blanks within literal constants should not
                    be allowed
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ripero84 at gmail dot com
  Target Milestone: ---

I belive that when writing free source form and using kind parameters as part
of integer, real, logical or character literal constants, there cannot be any
blanks between the underscore and the kind-param, or between the underscore and
the rest of characters that are part of the same literal constant.  This means
that, e.g.,

3.1415_4

is a valid real literal constant (if 4 is a valid real kind), but

3.1415 _4
3.1415_ 4

are not - and these don't have an possible interpretations as valid Fortran.

My interpretation is based on the following sections and rules of the Fortran
2018 standard:
* 6.2.1: "A lexical token is a keyword, name, literal constant other than a
complex literal constant [...]"
* 6.3.2.2: "In free source form blank characters shall not appear within
lexical tokens other than in a character context or in a format specification."
* R708, R714, and R725 establish that a trailing _kind-param is an optional
part of int-literal-constants, real-literal-constants, and
logical-literal-constants, respectively.
* R724 establishes that a leading kind-param_ is an optional part of a
char-literal-constant.

As far as I can see, these requirements go back all the way to the first
version of the standard that supported free source form, Fortran 90.

Unfortunately, all the versions of gfortran I've tried so far (9.2.1 20191109,
8.3.0, 7.5.0, 6.4.0 20181019), irrespective of the use of one of the -std=
flags or none, fail to detect the presence of blanks at one or both of the
sides of the underscore, and happily compile the source code.  This happens
also irrespective of whether the kind-param is numeric (3.1415_4) or an integer
variable with the parameter attribute

INTEGER, PARAMETER :: k = KIND(1.0)
WRITE(*,*) 3.1415_k ! valid Fortran
WRITE(*,*) 3.1415 _k ! invalid Fortran not detected by gfortran

with the only exception of character literal constants, where gfortran actually
produces an error if one attempts to compile code where spaces are present and
the kind-param is given by a variable:

WRITE(*,*) 4_ 'b' ! invalid Fortran not detected by gfortran
INTEGER, PARAMETER :: k = KIND('a')
WRITE(*,*) k_ 'b' ! invalid Fortran detected by gfortran

Reply via email to