https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105371
--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Wed, Apr 27, 2022 at 07:51:10PM +0000, anlauf at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105371 > > --- Comment #4 from anlauf at gcc dot gnu.org --- > The following untested hackish patch leads to the same answer for both cases: > > diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc > index 233cc42137f..abd93956217 100644 > --- a/gcc/fortran/simplify.cc > +++ b/gcc/fortran/simplify.cc > @@ -4946,7 +4946,8 @@ gfc_simplify_merge (gfc_expr *tsource, gfc_expr > *fsource, > gfc_expr *mask) > { > result = gfc_copy_expr (mask->value.logical ? tsource : fsource); > /* Parenthesis is needed to get lower bounds of 1. */ > - result = gfc_get_parentheses (result); > + if (result->rank) > + result = gfc_get_parentheses (result); > gfc_simplify_expr (result, 1); > return result; > } > > Thing is, I have to find a compiler that gives the result the reporter > expects. > E.g. Intel 2021.5 prints > > 1 > > for both cases. > Harald, thanks for looking at this! I don't use polymorphism in my codes. The "class(t) :: x, y, r" declaration clearly gives x, y, r the type type(t). I assume that the assignments "x = t2(1,-1)" and "y = t2(2,-2)" now change the dynamic type of x and y to type(t2). When "r = merge(x,y,...)" is evaluated and assigned the dynamic type of r becomes type(t2). So, the output should be 1 -1 But, again, I'm not polymorphic.