[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / return-stack-addr-2.cpp
blobfb810902d5e3bdbb1f6756d20cf82018e2f41028
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
4 namespace PR26599 {
5 template <typename>
6 struct S;
8 struct I {};
10 template <typename T>
11 void *&non_pointer() {
12 void *&r = S<T>()[I{}];
13 return r;
16 template <typename T>
17 void *&pointer() {
18 void *&r = S<T>()[nullptr];
19 return r;
23 namespace LocalTemporary {
25 template <class T>
26 class QMap {
27 public:
28 T value(const T &t = T()) const {
29 return t;
33 struct A {};
35 void test() {
36 QMap<A *> map;
37 map.value();
40 typedef int* ptr;
41 ptr int1(const ptr &p = ptr()) {
42 return (p);
45 ptr int2(const ptr &p = nullptr) {
46 return p;
49 ptr int3() {
50 const ptr &p = ptr();
51 return p;
54 const int *int4(const int &x = 5) {
55 return &x;
58 const int *int5(const int &x) {
59 return &x;
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}}
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}}
72 const int *int8(const int &x = 5) {
73 const int &x2 = x;
74 return &x2;
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}}