public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fortran/67802 -- Numeric constant character length must ...
@ 2015-10-01 18:54 Steve Kargl
  2015-10-01 19:19 ` FX
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Kargl @ 2015-10-01 18:54 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

be an integer expression.

The attached patch checks that a numerical constant in
a CHARACTER(LEN=x) declaration is an integer.  Regression
tested on x86_64-*-freebsd*.  OK to commit?

2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67802
	* decl.c (add_init_expr_to_sym): Numeric constant for character
	length must be an INTEGER.

2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67802
	* gfortran.dg/pr67802.f90: New test.

-- 
Steve

[-- Attachment #2: pr67802.diff --]
[-- Type: text/x-diff, Size: 1485 bytes --]

Index: fortran/decl.c
===================================================================
--- fortran/decl.c	(revision 228306)
+++ fortran/decl.c	(working copy)
@@ -1439,7 +1439,16 @@ add_init_expr_to_sym (const char *name, 
 	  /* Update initializer character length according symbol.  */
 	  else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)
 	    {
-	      int len = mpz_get_si (sym->ts.u.cl->length->value.integer);
+	      int len;
+
+	      if (sym->ts.u.cl->length->ts.type != BT_INTEGER)
+		{
+		  gfc_error ("Expecting an scalar-int-expr at %L",
+			     &sym->ts.u.cl->length->where);
+		  return false;
+		}
+
+	      len = mpz_get_si (sym->ts.u.cl->length->value.integer);
 
 	      if (init->expr_type == EXPR_CONSTANT)
 		gfc_set_constant_character_len (len, init, -1);
Index: testsuite/gfortran.dg/pr67802.f90
===================================================================
--- testsuite/gfortran.dg/pr67802.f90	(revision 0)
+++ testsuite/gfortran.dg/pr67802.f90	(working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/67802
+! Original code contribute by gerhard.steinmetz.fortran at t-online.de
+program p
+   character(1.) :: c1 = ' '      ! { dg-error "Expecting an scalar-int-expr" }
+   character(1d1) :: c2 = ' '     ! { dg-error "Expecting an scalar-int-expr" }
+   character((0.,1.)) :: c3 = ' ' ! { dg-error "Expecting an scalar-int-expr" }
+   character(.true.) :: c4 = ' '  ! { dg-error "Expecting an scalar-int-expr" }
+end program p

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

* Re: [PATCH] fortran/67802 -- Numeric constant character length must ...
  2015-10-01 18:54 [PATCH] fortran/67802 -- Numeric constant character length must Steve Kargl
@ 2015-10-01 19:19 ` FX
  2015-10-01 19:45   ` Steve Kargl
  0 siblings, 1 reply; 6+ messages in thread
From: FX @ 2015-10-01 19:19 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

> 2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67802
> 	* decl.c (add_init_expr_to_sym): Numeric constant for character
> 	length must be an INTEGER.
> 
> 2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67802
> 	* gfortran.dg/pr67802.f90: New test.

OK, but not with that error message. We currently don’t use the “shorthand” standard notation (like "scalar-int-expr”) in our error messages, and we should keep that consistent. So I would go with “character length should be of integer type” or something like that.

FX

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

* Re: [PATCH] fortran/67802 -- Numeric constant character length must ...
  2015-10-01 19:19 ` FX
@ 2015-10-01 19:45   ` Steve Kargl
  2015-10-01 20:49     ` FX
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Kargl @ 2015-10-01 19:45 UTC (permalink / raw)
  To: FX; +Cc: fortran, gcc-patches

On Thu, Oct 01, 2015 at 09:19:15PM +0200, FX wrote:
> > 2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>
> > 
> > 	PR fortran/67802
> > 	* decl.c (add_init_expr_to_sym): Numeric constant for character
> > 	length must be an INTEGER.
> > 
> > 2015-10-01  Steven G. Kargl  <kargl@gcc.gnu.org>
> > 
> > 	PR fortran/67802
> > 	* gfortran.dg/pr67802.f90: New test.
> 
> OK, but not with that error message. We currently don???t use
> the ???shorthand??? standard notation (like "scalar-int-expr???)
> in our error messages, and we should keep that consistent.
> So I would go with ???character length should be of integer
> type??? or something like that.
> 

Well, ahem, gfortran does have several error messages that use the
standard notation.  I know.  I wrote some of them. :-)

I'll simply change it to "Expecting an INTEGER at %L"

-- 
Steve

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

* Re: [PATCH] fortran/67802 -- Numeric constant character length must ...
  2015-10-01 19:45   ` Steve Kargl
@ 2015-10-01 20:49     ` FX
  0 siblings, 0 replies; 6+ messages in thread
From: FX @ 2015-10-01 20:49 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

> Well, ahem, gfortran does have several error messages that use the
> standard notation.  I know.  I wrote some of them. :-)
> 
> I'll simply change it to "Expecting an INTEGER at %L”

Thanks. I have no objections to using the full standard terminology (scalar integer expression), but not the shorthand (scalar-int-expr) which few people outside the language lawyers know :)

FX

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

* Re: [PATCH] fortran/67802 -- Numeric constant character length must ...
  2015-10-01 21:19 Dominique d'Humières
@ 2015-10-01 23:25 ` Steve Kargl
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Kargl @ 2015-10-01 23:25 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: FX Coudert, GNU GFortran, GCC Patches

On Thu, Oct 01, 2015 at 11:19:37PM +0200, Dominique d'Humières wrote:
> Without initialization the errors are of the kind:
> 
> Error: Expression at (1) must be of INTEGER type, found *
> 
> see https://gcc.gnu.org/ml/gcc-bugs/2015-10/msg00081.html. Should not we get the same message with initialization?
> 

Ugh, that message is horrible.  IMHO, everything after the comma
(your ", found *") is an abmonition.


-- 
Steve

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

* Re: [PATCH] fortran/67802 -- Numeric constant character length must ...
@ 2015-10-01 21:19 Dominique d'Humières
  2015-10-01 23:25 ` Steve Kargl
  0 siblings, 1 reply; 6+ messages in thread
From: Dominique d'Humières @ 2015-10-01 21:19 UTC (permalink / raw)
  To: Steve Kargl; +Cc: FX Coudert, GNU GFortran, GCC Patches

Without initialization the errors are of the kind:

Error: Expression at (1) must be of INTEGER type, found *

see https://gcc.gnu.org/ml/gcc-bugs/2015-10/msg00081.html. Should not we get the same message with initialization?

Cheers,

Dominique

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

end of thread, other threads:[~2015-10-01 23:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-01 18:54 [PATCH] fortran/67802 -- Numeric constant character length must Steve Kargl
2015-10-01 19:19 ` FX
2015-10-01 19:45   ` Steve Kargl
2015-10-01 20:49     ` FX
2015-10-01 21:19 Dominique d'Humières
2015-10-01 23:25 ` Steve Kargl

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).