This is valid code, however, the values in the array do all have length 9. All of the strings in that array are the same length, some of them are just automatically padded with “blanks”. I’ve got an example about why this might not be the best idea.
program main
use iso_fortran_env, only: character_kinds
implicit none
integer, parameter :: c1 = character_kinds(1), c2 = character_kinds(2)
character(len=5, kind = c1), parameter :: foo1 = "foo"
character(len=5, kind = c2), parameter :: foo2 = "foo"
print *, foo1 == foo2
print *, foo1 == "foo"
print *, foo2 == "foo"
end program
It is not defined whether this program will print T or F for any of the 3 expressions. Specifically, the blank character is only specified to be space for characters of default kind (i.e. the “foo” literals on the last 2 lines). The comparison operators say that the shorter character is padded with blanks to the length of the longer character, but those blanks could be different characters between different kinds. It is also not defined what the order of the kinds are in the character_kinds array, so either c1 or c2 or neither might be the default kind.
Granted I have not seen a processor that will actually print F for any of those, but it could and would still be considered standards conforming.