// { dg-do run } // Bug libstdc++/122907 // std::copy incorrectly uses memcpy when copying from signed or unsigned char // buffer to bool buffer #include #include template __attribute__((noinline,noipa)) void test_pr122907(T (&buf)[4]) { unsigned char uc[4]; bool bool_buf[4]; std::copy(buf, buf+1, bool_buf); std::copy(bool_buf, bool_buf+1, uc); VERIFY(uc[0] == bool(buf[0])); std::copy(buf, buf+4, bool_buf); std::copy(bool_buf, bool_buf+4, uc); VERIFY(uc[0] == bool(buf[0])); VERIFY(uc[1] == bool(buf[1])); VERIFY(uc[2] == bool(buf[2])); VERIFY(uc[3] == bool(buf[3])); } template void test_pr122907() { T buf[4] = { (T)3, (T)2, (T)1, (T)0 }; test_pr122907(buf); } int main() { test_pr122907(); test_pr122907(); test_pr122907(); test_pr122907(); test_pr122907(); }