diff options
author | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
commit | 110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab (patch) | |
tree | 64a10f4c4154739d4a8191d7e1b52ce497f4ebd6 /test/SemaCXX/warn-non-pod-memset.cpp | |
parent | a0fb00f9837bd0d2e5948f16f6a6b82a7a628f51 (diff) | |
download | FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.zip FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.tar.gz |
Vendor import of clang trunk r130700:
http://llvm.org/svn/llvm-project/cfe/trunk@130700
Diffstat (limited to 'test/SemaCXX/warn-non-pod-memset.cpp')
-rw-r--r-- | test/SemaCXX/warn-non-pod-memset.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-non-pod-memset.cpp b/test/SemaCXX/warn-non-pod-memset.cpp new file mode 100644 index 0000000..fbdcead --- /dev/null +++ b/test/SemaCXX/warn-non-pod-memset.cpp @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -fsyntax-only -Wnon-pod-memset -verify %s + +extern void *memset(void *, int, unsigned); + +// Several POD types that should not warn. +struct S1 {} s1; +struct S2 { int x; } s2; +struct S3 { float x, y; S1 s[4]; void (*f)(S1**); } s3; + +// We use the C++11 concept of POD for this warning, so ensure a non-aggregate +// still warns. +class C1 { + int x, y, z; +public: + void foo() {} +} c1; + +// Non-POD types that should warn. +struct X1 { X1(); } x1; +struct X2 { ~X2(); } x2; +struct X3 { virtual void f(); } x3; +struct X4 : X2 {} x4; +struct X5 : virtual S1 {} x5; + +void test_warn() { + memset(&x1, 0, sizeof x1); // \ + // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + memset(&x2, 0, sizeof x2); // \ + // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + memset(&x3, 0, sizeof x3); // \ + // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + memset(&x4, 0, sizeof x4); // \ + // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + memset(&x5, 0, sizeof x5); // \ + // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} +} + +void test_nowarn(void *void_ptr) { + int i, *iptr; + float y; + char c; + + memset(&i, 0, sizeof i); + memset(&iptr, 0, sizeof iptr); + memset(&y, 0, sizeof y); + memset(&c, 0, sizeof c); + memset(void_ptr, 0, 42); + memset(&s1, 0, sizeof s1); + memset(&s2, 0, sizeof s2); + memset(&s3, 0, sizeof s3); + memset(&c1, 0, sizeof c1); + + // Unevaluated code shouldn't warn. + (void)sizeof memset(&x1, 0, sizeof x1); + + // Dead code shouldn't warn. + if (false) memset(&x1, 0, sizeof x1); +} |