Standard use of user-defined operators?

I had a mildy wild idea: can you define a user-defined operator that actually takes three arguments? Obviously, not directly, but an operator that clips a value between two bounds could look like:

    y = x .clip. [0.0, 2.0]

This works (see example code) with gfortran and flang. But ifx protests:

Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.0 Build 20241008
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

triple.f90(32): error #6535: This variable or component must be of a derived or structure type.   [X]
    write(*,*) x .clip. [0.0, 2.0]

Quite probably due to the support of a non-standard style of defining structures and the like, but my question is: is this standard complying?
triple.f90 (697 Bytes)

I believe it is.

1 Like

If you need a workaround, this works (Compiler Explorer):

    real :: x, r(2)

    r = [0.0, 2.0]
    x = 1.0

! Workaround 1
    write(*,*) x .clip. r

! Workaround 2
    associate(t => [0.0,2.0])
        write(*,*) x.clip.t
    end associate

Another workaround:

    write(*,*) (x .clip. [0.0, 2.0])
    write(*,*) (x .clip. [0.0, 0.5])
1 Like

That’s a good one!

Well, the most important points:

  • The operator is valid (that was my main question)
  • The ifx compiler is misinterpreting the code

Thanks for looking into this.