1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memaccess %s
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
);
8 class TriviallyCopyable
{};
9 class NonTriviallyCopyable
{ NonTriviallyCopyable(const NonTriviallyCopyable
&);};
12 void test_bzero(TriviallyCopyable
* tc
,
13 NonTriviallyCopyable
*ntc
,
16 bzero(tc
, sizeof(*tc
));
21 // expected-warning@+2{{first argument in call to 'bzero' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}}
22 // expected-note@+1{{explicitly cast the pointer to silence this warning}}
23 bzero(ntc
, sizeof(*ntc
));
26 bzero((void*)ntc
, sizeof(*ntc
));
29 void test_memset(TriviallyCopyable
* tc
,
30 NonTriviallyCopyable
*ntc
,
33 memset(tc
, 0, sizeof(*tc
));
38 // expected-warning@+2{{first argument in call to 'memset' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}}
39 // expected-note@+1{{explicitly cast the pointer to silence this warning}}
40 memset(ntc
, 0, sizeof(*ntc
));
43 memset((void*)ntc
, 0, sizeof(*ntc
));
47 void test_memcpy(TriviallyCopyable
* tc0
, TriviallyCopyable
* tc1
,
48 NonTriviallyCopyable
*ntc0
, NonTriviallyCopyable
*ntc1
,
49 Incomplete
*i0
, Incomplete
*i1
) {
51 memcpy(tc0
, tc1
, sizeof(*tc0
));
56 // expected-warning@+2{{first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}}
57 // expected-note@+1{{explicitly cast the pointer to silence this warning}}
58 memcpy(ntc0
, ntc1
, sizeof(*ntc0
));
61 memcpy((void*)ntc0
, ntc1
, sizeof(*ntc0
));
64 memcpy((void*)ntc0
, (void*)ntc1
, sizeof(*ntc0
));
67 void test_memmove(TriviallyCopyable
* tc0
, TriviallyCopyable
* tc1
,
68 NonTriviallyCopyable
*ntc0
, NonTriviallyCopyable
*ntc1
,
69 Incomplete
*i0
, Incomplete
*i1
) {
71 memmove(tc0
, tc1
, sizeof(*tc0
));
76 // expected-warning@+2{{first argument in call to 'memmove' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}}
77 // expected-note@+1{{explicitly cast the pointer to silence this warning}}
78 memmove(ntc0
, ntc1
, sizeof(*ntc0
));
81 memmove((void*)ntc0
, ntc1
, sizeof(*ntc0
));
84 memmove((void*)ntc0
, (void*)ntc1
, sizeof(*ntc0
));