[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / return-stack-addr-2.cpp
blobe848189bde787c435dc2388c205e5c4e3d50107f
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s
3 namespace PR26599 {
4 template <typename>
5 struct S;
7 struct I {};
9 template <typename T>
10 void *&non_pointer() {
11 void *&r = S<T>()[I{}];
12 return r;
15 template <typename T>
16 void *&pointer() {
17 void *&r = S<T>()[nullptr];
18 return r;
22 namespace LocalTemporary {
24 template <class T>
25 class QMap {
26 public:
27 T value(const T &t = T()) const {
28 return t;
32 struct A {};
34 void test() {
35 QMap<A *> map;
36 map.value();
39 typedef int* ptr;
40 ptr int1(const ptr &p = ptr()) {
41 return (p);
44 ptr int2(const ptr &p = nullptr) {
45 return p;
48 ptr int3() {
49 const ptr &p = ptr();
50 return p;
53 const int *int4(const int &x = 5) {
54 return &x;
57 const int *int5(const int &x) {
58 return &x;
61 const int *int6() {
62 const int &x = 11; //expected-note{{binding reference variable 'x' here}}
63 return &x; //expected-warning{{returning address of local temporary object}}
66 const int *int7(int x) {
67 const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
68 return &x2; // expected-warning{{address of stack memory associated with parameter 'x' returned}}
71 const int *int8(const int &x = 5) {
72 const int &x2 = x;
73 return &x2;
76 const int *int9() {
77 const int &x = 5; // expected-note{{binding reference variable 'x' here}}
78 const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
79 return &x2; // expected-warning{{returning address of local temporary object}}