86 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memcall %s2 3extern "C" void *bzero(void *, unsigned);4extern "C" void *memset(void *, int, unsigned);5extern "C" void *memmove(void *s1, const void *s2, unsigned n);6extern "C" void *memcpy(void *s1, const void *s2, unsigned n);7 8class TriviallyCopyable {};9class NonTriviallyCopyable { NonTriviallyCopyable(const NonTriviallyCopyable&);};10struct Incomplete;11 12void test_bzero(TriviallyCopyable* tc,13 NonTriviallyCopyable *ntc,14 Incomplete* i) {15 // OK16 bzero(tc, sizeof(*tc));17 18 // OK19 bzero(i, 10);20 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));24 25 // OK26 bzero((void*)ntc, sizeof(*ntc));27}28 29void test_memset(TriviallyCopyable* tc,30 NonTriviallyCopyable *ntc,31 Incomplete* i) {32 // OK33 memset(tc, 0, sizeof(*tc));34 35 // OK36 memset(i, 0, 10);37 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));41 42 // OK43 memset((void*)ntc, 0, sizeof(*ntc));44}45 46 47void test_memcpy(TriviallyCopyable* tc0, TriviallyCopyable* tc1,48 NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1,49 Incomplete *i0, Incomplete *i1) {50 // OK51 memcpy(tc0, tc1, sizeof(*tc0));52 53 // OK54 memcpy(i0, i1, 10);55 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));59 60 // ~ OK61 memcpy((void*)ntc0, ntc1, sizeof(*ntc0));62 63 // OK64 memcpy((void*)ntc0, (void*)ntc1, sizeof(*ntc0));65}66 67void test_memmove(TriviallyCopyable* tc0, TriviallyCopyable* tc1,68 NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1,69 Incomplete *i0, Incomplete *i1) {70 // OK71 memmove(tc0, tc1, sizeof(*tc0));72 73 // OK74 memmove(i0, i1, 10);75 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));79 80 // ~ OK81 memmove((void*)ntc0, ntc1, sizeof(*ntc0));82 83 // OK84 memmove((void*)ntc0, (void*)ntc1, sizeof(*ntc0));85}86