in the following example, should the program not behave the same way,whether I assign a variable to itself enclosed or not in parentheses ?
module m_test type t_1 integer :: i,j,k contains procedure, private :: t_1_ass_t_1 generic :: assignment(=) => t_1_ass_t_1 end type contains subroutine t_1_ass_t_1(var, expr) class(t_1), intent(out) :: var class(t_1), intent(in) :: expr var%i = 0 var%j = 0 var%k = 0 if (expr%i > 0) then var%i = expr%i var%j = expr%j var%k = expr%k endif end subroutine end module program test use m_test type(t_1) :: x,y x = t_1(1,2,3) x = x print *, x y = t_1(1,2,3) y = (y) print *, y end program
However the output is:
C:\TEMP>ifort test.f90 Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.110 Build 20150815 Copyright (C) 1985-2015 Intel Corporation. All rights reserved. Microsoft (R) Incremental Linker Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. -out:test.exe -subsystem:console test.obj C:\TEMP>test 0 0 0 1 2 3 C:\TEMP>
In clause 12.4.3.4.3 the Fortran 2008 standard says "A defined assignment is treated as a reference to the subroutine, with the left-hand side as the first argument and the right-hand side enclosed in parentheses as the second argument."
Johny