1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s 2 3 namespace PR26599 { 4 template <typename> 5 struct S; 6 7 struct I {}; 8 9 template <typename T> 10 void *&non_pointer() { 11 void *&r = S<T>()[I{}]; 12 return r; 13 } 14 15 template <typename T> 16 void *&pointer() { 17 void *&r = S<T>()[nullptr]; 18 return r; 19 } 20 } 21 22 namespace LocalTemporary { 23 24 template <class T> 25 class QMap { 26 public: 27 T value(const T &t = T()) const { 28 return t; 29 } 30 }; 31 32 struct A {}; 33 34 void test() { 35 QMap<A *> map; 36 map.value(); 37 } 38 39 typedef int* ptr; 40 ptr int1(const ptr &p = ptr()) { 41 return (p); 42 } 43 44 ptr int2(const ptr &p = nullptr) { 45 return p; 46 } 47 48 ptr int3() { 49 const ptr &p = ptr(); 50 return p; 51 } 52 53 const int *int4(const int &x = 5) { 54 return &x; 55 } 56 57 const int *int5(const int &x) { 58 return &x; 59 } 60 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}} 64 } 65 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}} 69 } 70 71 const int *int8(const int &x = 5) { 72 const int &x2 = x; 73 return &x2; 74 } 75 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}} 80 } 81 } 82