Fix build with clang+libc++, based on patches by joerg.