https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68993
Bug ID: 68993 Summary: MERGE does not evaluate its arguments Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: Joost.VandeVondele at mat dot ethz.ch Target Milestone: --- I'm not 100% sure what the right answer is, i.e. if MERGE is defined by the standard to do something special with respect to evaluating its arguments. The origin is code like this: MERGE(C_NULL_PTR, C_LOC(pc), .NOT.PRESENT(pc))) is this standard conforming if pc is not present ? In that case MERGE is supposed to return C_NULL_PTR, but I see no reason why C_LOC(pc) would not be evaluated first. Gfortran and ifort behave differently in this respect.In the below code ifort calls foo 4x while gfortran calls it 2x. While gfortran's way of doing things seem natural, I suspect it is not standard conforming. > cat test.f90 MODULE test INTEGER, SAVE :: i=0 CONTAINS INTEGER FUNCTION foo() i=i+1 foo=i END FUNCTION END MODULE test USE test WRITE(6,*) MERGE(foo(),foo(),.FALSE.) WRITE(6,*) MERGE(foo(),foo(),.FALSE.) WRITE(6,*) i END > gfortran test.f90 && ./a.out 1 2 2 > ifort test.f90 && ./a.out 2 4 4