blob: 03e626e70877f3d85e09861e1ba72820e64d260f [file] [log] [blame]
Chandler Carruth7ccc95b2011-04-27 07:05:31 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3extern void *memset(void *, int, unsigned);
4
5// Several POD types that should not warn.
6struct S1 {} s1;
7struct S2 { int x; } s2;
8struct S3 { float x, y; S1 s[4]; void (*f)(S1**); } s3;
9
10// Non-POD types that should warn.
11struct X1 { X1(); } x1;
12struct X2 { ~X2(); } x2;
13struct X3 { virtual void f(); } x3;
14struct X4 : X2 {} x4;
15struct X5 : virtual S1 {} x5;
16
17void test_warn() {
18 memset(&x1, 0, sizeof x1); // \
19 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
20 // expected-note {{explicitly cast the pointer to silence this warning}}
21 memset(&x2, 0, sizeof x2); // \
22 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
23 // expected-note {{explicitly cast the pointer to silence this warning}}
24 memset(&x3, 0, sizeof x3); // \
25 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
26 // expected-note {{explicitly cast the pointer to silence this warning}}
27 memset(&x4, 0, sizeof x4); // \
28 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
29 // expected-note {{explicitly cast the pointer to silence this warning}}
30 memset(&x5, 0, sizeof x5); // \
31 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
32 // expected-note {{explicitly cast the pointer to silence this warning}}
33}
34
35void test_nowarn() {
36 memset(&s1, 0, sizeof s1);
37 memset(&s2, 0, sizeof s2);
38 memset(&s3, 0, sizeof s3);
39
40 // Unevaluated code shouldn't warn.
41 (void)sizeof memset(&x1, 0, sizeof x1);
42
43 // Dead code shouldn't warn.
44 if (false) memset(&x1, 0, sizeof x1);
45}