Hi Tobias,

I have some updates about this patch.

First, some good news:
1. The patch has been bootstrapped and tested with no regressions.
This was achieved by limiting the type with only one 'sorry' case.
2. The frontend parsing now considers outer parentheses.

And we also have some unresolved problems.
1. First is the use of a conditional expression as an argument.
Consider the following code example: it will compile but produce an
incorrect result. The reason is that the current implementation passes
the address of a local output to the function, rather than the address
of the true_expr or false_expr. Based on our previous discussion, we
don't need to necessarily handle this in the current patch; I just
wanted to highlight it. I will investigate how the argument-passing
logic works.

program conditional_arg
  implicit none
  call five((a < 5 ? a : b))
contains
  subroutine five(x)
    integer, optional :: x
    if (present(x)) then
      x = 5
    end if
  end subroutine five
end program conditional_arg

2. The diagnostic location appears to have an off-by-one error.
Consider the diagnostic for conditional_4.f90. Ideally, I'd like
points (1) and (2) to reference the true_expr and false_expr,
respectively. However, the current output is odd: (1) points to the
'?' and (2) points to the ':', which is not what I expected.

/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:13:7:

   13 |   i = (l1 ? 1 : -1) ! { dg-error "Condition in conditional
expression must be a scalar logical" }
      |       1
Error: Condition in conditional expression must be a scalar logical at (1)
/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:14:7:

   14 |   i = (i ? 1 : -1) ! { dg-error "Condition in conditional
expression must be a scalar logical" }
      |       1
Error: Condition in conditional expression must be a scalar logical at (1)
/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:15:15-19:

   15 |   i = (i /= 0 ? 1 : "oh no") ! { dg-error "must have the same
declared type" }
      |               1   2
Error: true_expr at (1) and false_expr at (2) in conditional
expression must have the same declared type
/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:16:15-20:

   16 |   i = (i /= 0 ? k1 : k4) ! { dg-error "must have the same kind
parameter" }
      |               1    2
Error: true_expr at (1) and false_expr at (2) in conditional
expression must have the same kind parameter
/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:17:15-22:

   17 |   i = (i /= 0 ? a_1d : a_2d) ! { dg-error "must have the same rank" }
      |               1      2
Error: true_expr at (1) and false_expr at (2) in conditional
expression must have the same rank
/gcc/gcc/testsuite/gfortran.dg/conditional_4.f90:18:8:

   18 |   k1 = (i /= 0 ? k1 : k1) ! { dg-error "currently only support
integer, logical, and real types" }
      |        1
Error: Sorry, conditional expression at (1) currently only support
integer, logical, and real types

I will investigate these issues and look forward to your further suggestions.

Thanks,
Yuao

Attachment: conditional.diff
Description: Binary data

Reply via email to