Tobias,

Thanks for checking this.  I will wait until the next patch has stabilized and 
is applied to the trunk, then build a new version.

I think many will want to use this feature in conjunction with optional 
arguments.  Hence it might be a good idea to add a unit test for the use case.  
Here is a simple example - is working fine:


program cond_expr
  implicit none
  integer :: ival

  ival = init ()
! print *, (ival == -99 ? "pass" : "fail") ! char type not supported yet
  print *, merge ("pass", "fail", ival == -99)

  ival = init (42)
! print *, (ival == 42 ? "pass" : "fail") ! char type not supported yet
  print *, merge ("pass", "fail", ival == 42)

contains

  integer function init (i)
    integer, intent(in), optional :: i

    init = (present (i) ? i : -99)

  end function
end program

When the next patch is ready, and character strings are supported, those two 
print statements could be switched from using MERGE to conditional expressions.

Walter

-----Original Message-----
From: Tobias Burnus <[email protected]>
Sent: Sep 22, 2025 11:13 AM
To: Walter Spector <[email protected]>, <[email protected]>
Subject: Re: [PATCH] fortran: implement conditional expression for fortran 2023

Hi Walter,

Walter Spector wrote:
> I'm really looking forward to conditional expressions because I like > using 
> them in other languages.  So I built a gfortran from the trunk a > few days 
> ago to test the mod.
>
> Here is a simple test case that compiles, but SEGVs at run-time:

This seems to be fixed by Yuao's latest patch. In one of my local branches, I 
have it applied &ndash; in the other not. And the one that has it works, in the 
other, I get the segfault. Thus, it really must be that patch.

The patch is 
https://gcc.gnu.org/pipermail/gcc-patches/2025-September/695638.html and adds 
additionally support for the character type. Unfortunately, I found some 
follow-up issues that need to be fixed before character support is ready for 
prime time.

Thanks for testing!

Tobias



Reply via email to