http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55069
Bug #: 55069 Summary: [4.7/4.8 Regression] TRIM incorrectly optimized out for assignment to allocatable string Classification: Unclassified Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: minor Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: quanthe...@gmail.com With -ffrontend-optimize turned on, in the following assignments, "str" is allocated to a larger size than it should have: character(len=2) :: blah character(len=:), allocatable :: str blah = "a" ! With -O, str will be set to "a ", else str == "a" str = trim(blah) ! No effect with -O str = trim(str) ! With -O str will be set to "ba ", else "ba" str = "b"//trim(blah) ! This trim cannot be optimized out, so it yields "ab" either way. str = trim(blah)//"b" This problem with allocatable strings is noted in the original enhancement proposal (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40628), but apparently not addressed yet?