diff mbox

PR fortran/78479 -- allocate a charlen

Message ID 20161122205557.GA92090@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Nov. 22, 2016, 8:55 p.m. UTC
The patch and ChangeLog shuod be sufficient to explain the change.
Regression tested on x86_64-*-freebsd.  OK to commit?

2016-11-22  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/78479
	* expr.c (gfc_apply_init):  Allocate a charlen if needed.

2016-11-22  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/78479
	* gfortran.dg/pr78479.f90: New test.

-- 
Steve

Comments

Janus Weil Nov. 22, 2016, 9:21 p.m. UTC | #1
Hi Steve,

> The patch and ChangeLog shuod be sufficient to explain the change.

> Regression tested on x86_64-*-freebsd.  OK to commit?


the patch itself looks good.

For the test case, I'd prefer a somewhat more meaningful name (e.g.
char_component_initializer_3.f90 or similar) and a mention of the PR
number in a comment inside the test case.

Thanks,
Janus



> 2016-11-22  Steven G. Kargl  <kargl@gcc.gnu.org>

>

>         PR fortran/78479

>         * expr.c (gfc_apply_init):  Allocate a charlen if needed.

>

> 2016-11-22  Steven G. Kargl  <kargl@gcc.gnu.org>

>

>         PR fortran/78479

>         * gfortran.dg/pr78479.f90: New test.

>

> --

> Steve
Steve Kargl Nov. 22, 2016, 9:46 p.m. UTC | #2
On Tue, Nov 22, 2016 at 10:21:52PM +0100, Janus Weil wrote:
> 

> > The patch and ChangeLog shuod be sufficient to explain the change.

> > Regression tested on x86_64-*-freebsd.  OK to commit?

> 

> the patch itself looks good.

> 


Thanks.

> For the test case, I'd prefer a somewhat more meaningful name (e.g.

> char_component_initializer_3.f90 or similar) and a mention of the PR

> number in a comment inside the test case.


At one time, I also preferred a meaningful name, but have
changed over time to using the PR number as the name.  There
are various pros and cons for using the PR number as the name.
In this, as char*_[1,2].f90 already exist, I rename the testcase.

-- 
Steve
diff mbox

Patch

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 242638)
+++ gcc/fortran/expr.c	(working copy)
@@ -4132,7 +4132,12 @@  gfc_apply_init (gfc_typespec *ts, symbol
                 {
                   gfc_set_constant_character_len (len, ctor->expr,
                                                   has_ts ? -1 : first_len);
-                  ctor->expr->ts.u.cl->length = gfc_copy_expr (ts->u.cl->length);
+		  if (!ctor->expr->ts.u.cl)
+		    ctor->expr->ts.u.cl
+		      = gfc_new_charlen (gfc_current_ns, ts->u.cl);
+		  else
+                    ctor->expr->ts.u.cl->length
+		      = gfc_copy_expr (ts->u.cl->length);
                 }
             }
         }
Index: gcc/testsuite/gfortran.dg/pr78479.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr78479.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr78479.f90	(working copy)
@@ -0,0 +1,6 @@ 
+! { dg-do compile }
+program p
+   type t
+      character(3) :: c(1) = 'a' // ['b']
+   end type
+end