1 // RUN: %clang_cc1 -fsyntax-only -Wdangling-field -verify -std=c++11 %s 2 3 struct X { 4 X(int); 5 }; 6 struct Y { 7 operator X*(); 8 operator X&(); 9 }; 10 11 struct S { 12 int &x, *y; // expected-note {{reference member declared here}} \ 13 // expected-note {{pointer member declared here}} SS14 S(int i) 15 : x(i), // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}} 16 y(&i) {} // expected-warning {{initializing pointer member 'y' with the stack address of parameter 'i'}} SS17 S(int &i) : x(i), y(&i) {} // no-warning: reference parameter SS18 S(int *i) : x(*i), y(i) {} // no-warning: pointer parameter 19 }; 20 21 struct S2 { 22 const X &x; // expected-note {{reference member declared here}} S2S223 S2(int i) : x(i) {} // expected-error {{member 'x' binds to a temporary}} 24 }; 25 26 struct S3 { 27 X &x1, *x2; S3S328 S3(Y y) : x1(y), x2(y) {} // no-warning: conversion operator 29 }; 30 31 template <typename T> struct S4 { 32 T x; // expected-note {{reference member declared here}} S4S433 S4(int i) : x(i) {} // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}} 34 }; 35 36 template struct S4<int>; // no warning from this instantiation 37 template struct S4<int&>; // expected-note {{in instantiation}} 38 39 struct S5 { 40 const X &x; // expected-note {{here}} 41 }; 42 S5 s5 = { 0 }; // ok, lifetime-extended 43 44 struct S6 { 45 S5 s5; // expected-note {{here}} S6S646 S6() : s5 { 0 } {} // expected-error {{reference subobject of member 's5' binds to a temporary}} 47 }; 48 49 struct S7 : S5 { S7S750 S7() : S5 { 0 } {} // expected-error {{reference member 'x' binds to a temporary}} 51 }; 52 53 struct S8 { 54 int *p; S8S855 S8(int *a) : p(&a[0]) {} 56 }; 57