public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/27998]  New: character arrays: warn if erray constructor values have different lengths
@ 2006-06-12 13:21 tobias dot burnus at physik dot fu-berlin dot de
  2006-06-13 17:45 ` [Bug fortran/27998] " pault at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tobias dot burnus at physik dot fu-berlin dot de @ 2006-06-12 13:21 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1818 bytes --]

The following constructor seems to be invalid according to the Fortran 2003
standard:
  (/ 'Takata', 'Tanaka', 'Hayashi' /)
as first two strings are 6 whereas the last one is 7 character long.

NAG f95 fails with the following error:
Error: string.f90, line 3: Array constructor values have differing CHARACTER
lengths (6 and 7)
[f95 error termination]

Thus a warning would be nice, at least with -Wall, maybe even a default
warning.

In the Fortran 2003 standard, I cannot find the line which forbids the usage of
different length strings. However, in "NOTE 4.70" of implicitly states that it
is not allowed:

"An example of an array constructor that specifies a nonkind type parameter:
   (/ CHARACTER(LEN=7) :: ’Takata’, ’Tanaka’, ’Hayashi’ /)
In this constructor, without the type specification, it would have been
necessary to specify all of the constants with the same character length."

(This currently does not work in gfortran, see bug 27997.)

Example:
----------------------------
program test
  character(15) :: a(3)
  ! invalid as the constants have different character lengths
  a =  (/ 'Takata', 'Tanaka', 'Hayashi' /)
  ! This is valid Fortran 95/2003
  !a =  (/ 'Takata ', 'Tanaka ', 'Hayashi' /)
  ! And this is valid Fortran 2003
  !a = (/ character(len=7) :: 'Takata ', 'Tanaka ', 'Hayashi' /)
  print '(a)',a
end program test


-- 
           Summary: character arrays: warn if erray constructor values have
                    different lengths
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tobias dot burnus at physik dot fu-berlin dot de


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


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

* [Bug fortran/27998] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
@ 2006-06-13 17:45 ` pault at gcc dot gnu dot org
  2006-06-15  6:35 ` paul dot richard dot thomas at cea dot fr
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2006-06-13 17:45 UTC (permalink / raw)
  To: gcc-bugs



-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-06-13 17:25:48
               date|                            |


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


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

* [Bug fortran/27998] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
  2006-06-13 17:45 ` [Bug fortran/27998] " pault at gcc dot gnu dot org
@ 2006-06-15  6:35 ` paul dot richard dot thomas at cea dot fr
  2006-06-15 12:34 ` tobias dot burnus at physik dot fu-berlin dot de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paul dot richard dot thomas at cea dot fr @ 2006-06-15  6:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paul dot richard dot thomas at cea dot fr  2006-06-15 06:33 -------
(In reply to comment #0)
According to section 4.5 of the Fortran95 standard:

"If the ac-value expressions are of type character, each ac-value expression in
the array-constructor shall have the same character length parameter."

.....so, an error is definitely in order.

Paul


-- 


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


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

* [Bug fortran/27998] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
  2006-06-13 17:45 ` [Bug fortran/27998] " pault at gcc dot gnu dot org
  2006-06-15  6:35 ` paul dot richard dot thomas at cea dot fr
@ 2006-06-15 12:34 ` tobias dot burnus at physik dot fu-berlin dot de
  2006-06-30 13:13 ` paul dot richard dot thomas at cea dot fr
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tobias dot burnus at physik dot fu-berlin dot de @ 2006-06-15 12:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tobias dot burnus at physik dot fu-berlin dot de  2006-06-15 12:26 -------
> .....so, an error is definitely in order.

Maybe one could spit out a default warning and only with -std=f90 an error as
this is might be a commonly used Fortran extension. Or one simply always
regards it as error.

NAG's f95 gives even with -dusty an error

ifort gives not error/warning by default, unless -std95 is specified, then an
error message is given.

g95 gives no warning (not even with -Wall -Wextra) unless -std=f95 is used
(then it is an error)

Sun Studio's f95 gives always an error


-- 


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


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

* [Bug fortran/27998] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
                   ` (2 preceding siblings ...)
  2006-06-15 12:34 ` tobias dot burnus at physik dot fu-berlin dot de
@ 2006-06-30 13:13 ` paul dot richard dot thomas at cea dot fr
  2007-01-05 14:46 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paul dot richard dot thomas at cea dot fr @ 2006-06-30 13:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paul dot richard dot thomas at cea dot fr  2006-06-30 12:40 -------
Created an attachment (id=11784)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11784&action=view)
The beginnings of a fix for the PR

Thee attached is simple, only gives warnings but is way too verbose, as the
following demonstrates:

program test
  character(10) :: a(3)
  character(10) :: b(3)= (/ 'Takata ', 'Tanaka', 'Hayashi' /)
  character(4) :: c = "abcde"
  a =  (/ 'Takata', 'Tanaka ', 'Hayashi' /)
  a =  (/ 'Takata ', 'Tanaka ', 'Hayashi' /)
  b = "abc"
  c = "abcdefg"
end program test

More work needed!

Paul


-- 


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


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

* [Bug fortran/27998] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
                   ` (3 preceding siblings ...)
  2006-06-30 13:13 ` paul dot richard dot thomas at cea dot fr
@ 2007-01-05 14:46 ` pault at gcc dot gnu dot org
  2007-01-14 14:51 ` [Bug fortran/27998] [4.2 and 4.1 only] " pault at gcc dot gnu dot org
  2007-01-14 14:53 ` [Bug fortran/27998] [4.1 " pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-01-05 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2007-01-05 14:45 -------
Subject: Bug 27998

Author: pault
Date: Fri Jan  5 14:45:20 2007
New Revision: 120485

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120485
Log:
2007-01-05  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/23232
        * decl.c (gfc_in_match_data, gfc_set_in_match_data): New
        functions to signal that a DATA statement is being matched.
        (gfc_match_data): Call gfc_set_in_match_data on entry and on
        exit.
        * gfortran.h : Add prototypes for above.
        * expr.c (check_init_expr): Avoid check on parameter or
        variable if gfc_in_match_data is true.
        (gfc_match_init_expr): Do not call error on non-reduction of
        expression if gfc_in_match_data is true.

        PR fortran/27996
        PR fortran/27998
        * decl.c (gfc_set_constant_character_len): Add boolean arg to
        flag array constructor resolution.  Warn if string is being
        truncated.  Standard dependent error if string is padded. Set
        new arg to false for all three calls to
        gfc_set_constant_character_len.
        * match.h : Add boolean arg to prototype for
        gfc_set_constant_character_len.
        * gfortran.h : Add warn_character_truncation to gfc_options.
        * options.c (set_Wall): Set warn_character_truncation if -Wall
        is set.
        * resolve.c (resolve_code): Warn if rhs string in character
        assignment has to be truncated.
        * array.c (gfc_resolve_character_array_constructor): Set new
        argument to true for call to gfc_set_constant_character_len.

2007-01-05  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/23232
        * gfortran.dg/data_implied_do_1.f90: New test.

        PR fortran/27996
        PR fortran/27998
        * gfortran.dg/char_length_1.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/data_implied_do_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_length_1.f90


-- 


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


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

* [Bug fortran/27998] [4.2 and 4.1 only] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
                   ` (4 preceding siblings ...)
  2007-01-05 14:46 ` pault at gcc dot gnu dot org
@ 2007-01-14 14:51 ` pault at gcc dot gnu dot org
  2007-01-14 14:53 ` [Bug fortran/27998] [4.1 " pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-01-14 14:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pault at gcc dot gnu dot org  2007-01-14 14:50 -------
Subject: Bug 27998

Author: pault
Date: Sun Jan 14 14:49:50 2007
New Revision: 120772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120772
Log:
2007-01-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
            Paul Thomas  <pault@gcc.gnu.org>

        Back port from trunk

        PR fortran/30408
        * lang.opt: Add Wcharacter_truncation option.
        * options.c (gfc_init_options): Initialize
        gfc_option.warn_character_truncation to zero.
        (gfc_handle_option): Add case for OPT_Wcharacter_truncation.

        PR fortran/30408
        * resolve.c (resolve_code): Use the code->expr character length
        directly to set length of llen.

2007-01-14  Paul Thomas  <pault@gcc.gnu.org>

        Backports from trunk

        PR fortran/23232
        * decl.c (gfc_in_match_data, gfc_set_in_match_data): New
        functions to signal that a DATA statement is being matched.
        (gfc_match_data): Call gfc_set_in_match_data on entry and on
        exit.
        * gfortran.h : Add prototypes for above.
        * expr.c (check_init_expr): Avoid check on parameter or
        variable if gfc_in_match_data is true.
        (gfc_match_init_expr): Do not call error on non-reduction of
        expression if gfc_in_match_data is true.

        PR fortran/27996
        PR fortran/27998
        * decl.c (gfc_set_constant_character_len): Add boolean arg to
        flag array constructor resolution.  Warn if string is being
        truncated.  Standard dependent error if string is padded. Set
        new arg to false for all three calls to
        gfc_set_constant_character_len.
        * match.h : Add boolean arg to prototype for
        gfc_set_constant_character_len.
        * gfortran.h : Add warn_character_truncation to gfc_options.
        * options.c (set_Wall): Set warn_character_truncation if -Wall
        is set.
        * resolve.c (resolve_code): Warn if rhs string in character
        assignment has to be truncated.
        * array.c (gfc_resolve_character_array_constructor): Set new
        argument to true for call to gfc_set_constant_character_len.

        PR fortran/30410
        * trans-decl.c (gfc_sym_mangled_function_id): Module, external
        symbols must not have the module name prepended.

2007-01-14  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/23232
        * gfortran.dg/data_implied_do_1.f90: New test.

        PR fortran/27996
        PR fortran/27998
        * gfortran.dg/char_length_1.f90: New test.

        PR fortran/30410
        * gfortran.dg/external_procedures_2.f90: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/char_length_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/data_implied_do_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/external_procedures_2.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/array.c
    branches/gcc-4_2-branch/gcc/fortran/decl.c
    branches/gcc-4_2-branch/gcc/fortran/expr.c
    branches/gcc-4_2-branch/gcc/fortran/gfortran.h
    branches/gcc-4_2-branch/gcc/fortran/lang.opt
    branches/gcc-4_2-branch/gcc/fortran/match.h
    branches/gcc-4_2-branch/gcc/fortran/options.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/27998] [4.1 only] character arrays: warn if erray constructor values have different lengths
  2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
                   ` (5 preceding siblings ...)
  2007-01-14 14:51 ` [Bug fortran/27998] [4.2 and 4.1 only] " pault at gcc dot gnu dot org
@ 2007-01-14 14:53 ` pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-01-14 14:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pault at gcc dot gnu dot org  2007-01-14 14:53 -------
Fixed on trunk and 4.2

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
            Summary|[4.2 and 4.1 only] character|[4.1 only] character arrays:
                   |arrays: warn if erray       |warn if erray constructor
                   |constructor values have     |values have different
                   |different lengths           |lengths


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


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

end of thread, other threads:[~2007-01-14 14:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-12 13:21 [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths tobias dot burnus at physik dot fu-berlin dot de
2006-06-13 17:45 ` [Bug fortran/27998] " pault at gcc dot gnu dot org
2006-06-15  6:35 ` paul dot richard dot thomas at cea dot fr
2006-06-15 12:34 ` tobias dot burnus at physik dot fu-berlin dot de
2006-06-30 13:13 ` paul dot richard dot thomas at cea dot fr
2007-01-05 14:46 ` pault at gcc dot gnu dot org
2007-01-14 14:51 ` [Bug fortran/27998] [4.2 and 4.1 only] " pault at gcc dot gnu dot org
2007-01-14 14:53 ` [Bug fortran/27998] [4.1 " pault at gcc dot gnu dot 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).