(Here we assume reasonable and intuitive definitions of things in the question and imply similar in the answer.)
The statement
call stack%push_back(stack%pop() - stack%pop())
would indeed be invalid, for the reason stated in the question. However, it may be easier to see this in terms of the other restriction in the pair, not quoted (Fortran 2018 10.1.4, but similar in F2008):
if a function reference causes definition or undefinition of an actual argument of the function, that argument or any associated entities shall not appear elsewhere in the same statement.
The statement of concern is the same as
call stack%push_back(pop(stack) - pop(stack))
where it's quite clear that stack
is an actual argument and it appears more than once in the statement; stack
is defined by the function pop
.
Yes you will need to use different statements to have the desired effect. The approach given in the question is reasonable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…