brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · fb81090 Raw
83 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s2// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 -Wno-return-stack-address -Wreturn-local-addr %s3 4namespace PR26599 {5template <typename>6struct S;7 8struct I {};9 10template <typename T>11void *&non_pointer() {12  void *&r = S<T>()[I{}];13  return r;14}15 16template <typename T>17void *&pointer() {18  void *&r = S<T>()[nullptr];19  return r;20}21}22 23namespace LocalTemporary {24 25template <class T>26class QMap {27public:28  T value(const T &t = T()) const {29    return t;30  }31};32 33struct A {};34 35void test() {36  QMap<A *> map;37  map.value();38}39 40typedef int* ptr;41ptr int1(const ptr &p = ptr()) {42  return (p);43}44 45ptr int2(const ptr &p = nullptr) {46  return p;47}48 49ptr int3() {50  const ptr &p = ptr();51  return p;52}53 54const int *int4(const int &x = 5) {55  return &x;56}57 58const int *int5(const int &x) {59  return &x;60}61 62const 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 67const 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 72const int *int8(const int &x = 5) {73  const int &x2 = x;74  return &x2;75}76 77const 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