1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s
2 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 -Wno-return-stack-address -Wreturn-local-addr %s
3
4 namespace PR26599 {
5 template <typename>
6 struct S;
7
8 struct I {};
9
10 template <typename T>
non_pointer()11 void *&non_pointer() {
12 void *&r = S<T>()[I{}];
13 return r;
14 }
15
16 template <typename T>
pointer()17 void *&pointer() {
18 void *&r = S<T>()[nullptr];
19 return r;
20 }
21 }
22
23 namespace LocalTemporary {
24
25 template <class T>
26 class QMap {
27 public:
value(const T & t=T ()) const28 T value(const T &t = T()) const {
29 return t;
30 }
31 };
32
33 struct A {};
34
test()35 void test() {
36 QMap<A *> map;
37 map.value();
38 }
39
40 typedef int* ptr;
int1(const ptr & p=ptr ())41 ptr int1(const ptr &p = ptr()) {
42 return (p);
43 }
44
int2(const ptr & p=nullptr)45 ptr int2(const ptr &p = nullptr) {
46 return p;
47 }
48
int3()49 ptr int3() {
50 const ptr &p = ptr();
51 return p;
52 }
53
int4(const int & x=5)54 const int *int4(const int &x = 5) {
55 return &x;
56 }
57
int5(const int & x)58 const int *int5(const int &x) {
59 return &x;
60 }
61
int6()62 const int *int6() {
63 const int &x = 11; //expected-note{{binding reference variable 'x' here}}
64 return &x; //expected-warning{{returning address of local temporary object}}
65 }
66
int7(int x)67 const int *int7(int x) {
68 const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
69 return &x2; // expected-warning{{address of stack memory associated with parameter 'x' returned}}
70 }
71
int8(const int & x=5)72 const int *int8(const int &x = 5) {
73 const int &x2 = x;
74 return &x2;
75 }
76
int9()77 const int *int9() {
78 const int &x = 5; // expected-note{{binding reference variable 'x' here}}
79 const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
80 return &x2; // expected-warning{{returning address of local temporary object}}
81 }
82 }
83