| 1 | // { dg-do run } |
| 2 | |
| 3 | // Bug libstdc++/122907 |
| 4 | // std::copy incorrectly uses memcpy when copying from signed or unsigned char |
| 5 | // buffer to bool buffer |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <testsuite_hooks.h> |
| 9 | |
| 10 | template<typename T> |
| 11 | __attribute__((noinline,noipa)) |
| 12 | void |
| 13 | test_pr122907(T (&buf)[4]) |
| 14 | { |
| 15 | unsigned char uc[4]; |
| 16 | bool bool_buf[4]; |
| 17 | std::copy(buf, buf+1, bool_buf); |
| 18 | std::copy(bool_buf, bool_buf+1, uc); |
| 19 | VERIFY(uc[0] == bool(buf[0])); |
| 20 | std::copy(buf, buf+4, bool_buf); |
| 21 | std::copy(bool_buf, bool_buf+4, uc); |
| 22 | VERIFY(uc[0] == bool(buf[0])); |
| 23 | VERIFY(uc[1] == bool(buf[1])); |
| 24 | VERIFY(uc[2] == bool(buf[2])); |
| 25 | VERIFY(uc[3] == bool(buf[3])); |
| 26 | } |
| 27 | |
| 28 | template<typename T> |
| 29 | void |
| 30 | test_pr122907() |
| 31 | { |
| 32 | T buf[4] = { (T)3, (T)2, (T)1, (T)0 }; |
| 33 | test_pr122907(buf); |
| 34 | } |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | test_pr122907<char>(); |
| 39 | test_pr122907<signed char>(); |
| 40 | test_pr122907<unsigned char>(); |
| 41 | test_pr122907<bool>(); |
| 42 | test_pr122907<int>(); |
| 43 | } |