|
| 1 | +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memaccess %s |
| 2 | + |
| 3 | +extern "C" void *bzero(void *, unsigned); |
| 4 | +extern "C" void *memset(void *, int, unsigned); |
| 5 | +extern "C" void *memmove(void *s1, const void *s2, unsigned n); |
| 6 | +extern "C" void *memcpy(void *s1, const void *s2, unsigned n); |
| 7 | + |
| 8 | +class TriviallyCopyable {}; |
| 9 | +class NonTriviallyCopyable { NonTriviallyCopyable(const NonTriviallyCopyable&);}; |
| 10 | + |
| 11 | +void test_bzero(TriviallyCopyable* tc, |
| 12 | + NonTriviallyCopyable *ntc) { |
| 13 | + // OK |
| 14 | + bzero(tc, sizeof(*tc)); |
| 15 | + |
| 16 | + // expected-warning@+2{{first argument in call to 'bzero' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 17 | + // expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 18 | + bzero(ntc, sizeof(*ntc)); |
| 19 | + |
| 20 | + // OK |
| 21 | + bzero((void*)ntc, sizeof(*ntc)); |
| 22 | +} |
| 23 | + |
| 24 | +void test_memset(TriviallyCopyable* tc, |
| 25 | + NonTriviallyCopyable *ntc) { |
| 26 | + // OK |
| 27 | + memset(tc, 0, sizeof(*tc)); |
| 28 | + |
| 29 | + // expected-warning@+2{{first argument in call to 'memset' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 30 | + // expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 31 | + memset(ntc, 0, sizeof(*ntc)); |
| 32 | + |
| 33 | + // OK |
| 34 | + memset((void*)ntc, 0, sizeof(*ntc)); |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +void test_memcpy(TriviallyCopyable* tc0, TriviallyCopyable* tc1, |
| 39 | + NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1) { |
| 40 | + // OK |
| 41 | + memcpy(tc0, tc1, sizeof(*tc0)); |
| 42 | + |
| 43 | + // expected-warning@+2{{first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 44 | + // expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 45 | + memcpy(ntc0, ntc1, sizeof(*ntc0)); |
| 46 | + |
| 47 | + // ~ OK |
| 48 | + memcpy((void*)ntc0, ntc1, sizeof(*ntc0)); |
| 49 | + |
| 50 | + // OK |
| 51 | + memcpy((void*)ntc0, (void*)ntc1, sizeof(*ntc0)); |
| 52 | +} |
| 53 | + |
| 54 | +void test_memmove(TriviallyCopyable* tc0, TriviallyCopyable* tc1, |
| 55 | + NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1) { |
| 56 | + // OK |
| 57 | + memmove(tc0, tc1, sizeof(*tc0)); |
| 58 | + |
| 59 | + // expected-warning@+2{{first argument in call to 'memmove' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 60 | + // expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 61 | + memmove(ntc0, ntc1, sizeof(*ntc0)); |
| 62 | + |
| 63 | + // ~ OK |
| 64 | + memmove((void*)ntc0, ntc1, sizeof(*ntc0)); |
| 65 | + |
| 66 | + // OK |
| 67 | + memmove((void*)ntc0, (void*)ntc1, sizeof(*ntc0)); |
| 68 | +} |
0 commit comments