https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66742
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> --- A candidate patch has been posted to https://gcc.gnu.org/ml/gcc-patches/2015-07/msg00217.html With that fix your testcase segfaults, because you allocate n bytes not n*sizeof(Tp).