1 // RUN: clang-cc -fsyntax-only -verify %s
5 return &x; // expected-warning {{address of stack memory}}
8 int* ret_local_array() {
10 return x; // expected-warning {{address of stack memory}}
13 int* ret_local_array_element(int i) {
15 return &x[i]; // expected-warning {{address of stack memory}}
18 int *ret_local_array_element_reversed(int i) {
20 return &i[x]; // expected-warning {{address of stack memory}}
23 int* ret_local_array_element_const_index() {
25 return &x[2]; // expected-warning {{address of stack memory}}
28 int& ret_local_ref() {
30 return x; // expected-warning {{reference to stack memory}}
33 int* ret_local_addrOf() {
35 return &*&x; // expected-warning {{address of stack memory}}
38 int* ret_local_addrOf_paren() {
40 return (&(*(&x))); // expected-warning {{address of stack memory}}
43 int* ret_local_addrOf_ptr_arith() {
45 return &*(&x+1); // expected-warning {{address of stack memory}}
48 int* ret_local_addrOf_ptr_arith2() {
50 return &*(&x+1); // expected-warning {{address of stack memory}}
53 int* ret_local_field() {
55 return &a.x; // expected-warning {{address of stack memory}}
58 int& ret_local_field_ref() {
60 return a.x; // expected-warning {{reference to stack memory}}
63 int* ret_conditional(bool cond) {
66 return cond ? &x : &y; // expected-warning {{address of stack memory}}
69 int* ret_conditional_rhs(int *x, bool cond) {
71 return cond ? x : &y; // expected-warning {{address of stack memory}}
76 return (void*) &x; // expected-warning {{address of stack memory}}
79 int* ret_static_var() {
81 return &x; // no warning.
87 return &z; // no warning.
90 int* ret_parameter(int x) {
91 return &x; // expected-warning {{address of stack memory}}
95 void* ret_cpp_static_cast(short x) {
96 return static_cast<void*>(&x); // expected-warning {{address of stack memory}}
99 int* ret_cpp_reinterpret_cast(double x) {
100 return reinterpret_cast<int*>(&x); // expected-warning {{address of stack me}}
103 int* ret_cpp_reinterpret_cast_no_warning(long x) {
104 return reinterpret_cast<int*>(x); // no-warning
107 int* ret_cpp_const_cast(const int x) {
108 return const_cast<int*>(&x); // expected-warning {{address of stack memory}}
111 // TODO: test case for dynamic_cast. clang does not yet have
112 // support for C++ classes to write such a test case.