I think the original code is correct, and ifort has a bug.
program test3
use iso_fortran_env, only: compiler_version
character(:),allocatable:: stuff
stuff = repeat('%',len(compiler_version()//''))
print *,'percent = ',stuff
print *,'version = ',compiler_version()
end program test3
The above also works alright with ifort. Note that a zero-length character string is appended to the function result. That appears to be enough for ifort to dig itself out of whatever hole it was in.
$ ifort test3.f90 && a.out
percent =
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
version =
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel
(R) 64, Version 2021.7.0 Build 20220726_000000
Notice how ifort inserts new lines even within the character strings. That is allowed by list-directed i/o.