]> granicus.if.org Git - clang/commitdiff
Added test cases for the return-stack-address checker to test support
authorTed Kremenek <kremenek@apple.com>
Mon, 20 Aug 2007 16:28:05 +0000 (16:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 20 Aug 2007 16:28:05 +0000 (16:28 +0000)
for the following C++ casts: static_cast, reinterpret_cast, and const_cast.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41181 91177308-0d34-0410-b5e6-96231b3b80d8

test/Sema/return-stack-addr.cpp

index a613b6b9b606c96f706fbf5ff9754dc275f2af55..ce4c41bf7aa31526aabc927bc48be3a19c142155 100644 (file)
@@ -86,4 +86,28 @@ int z = 1;
 
 int* ret_global() {
   return &z;  // no warning.
-}
\ No newline at end of file
+}
+
+int* ret_parameter(int x) {
+  return &x;  // expected-warning {{address of stack memory}}
+}
+
+
+int* ret_cpp_static_cast(short x) {
+  return static_cast<int*>(&x); // expected-warning {{address of stack memory}}
+}
+
+int* ret_cpp_reinterpret_cast(double x) {
+  return reinterpret_cast<int*>(&x); // expected-warning {{address of stack me}}
+}
+
+int* ret_cpp_reinterpret_cast_no_warning(double x) {
+  return reinterpret_cast<int*>(x); // no-warning
+}
+
+int* ret_cpp_const_cast(const x) {
+  return const_cast<int*>(&x);  // expected-warning {{address of stack memory}}
+}
+
+// TODO: test case for dynamic_cast.  clang does not yet have
+// support for C++ classes to write such a test case.
\ No newline at end of file