https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80265
--- Comment #30 from Pedro Alves <palves at redhat dot com> --- > I suspect that wouldn't work, because we'd need to check whether the > elements the iterator range point-to are themselves constant. I would like to add that the char_traits trick handles this by doing exactly that, checking whether all elements in the string/array are constant (__constant_string_p/__constant_char_array_p), before deferring to the naive for loop; a __constexpr_memcmp would do the same before falling back to __builtin_memcmp. In my testing back then, the compiler/optimizer always folded away these loops.