1// RUN: %clang_cc1 -fsyntax-only -Wdangling-field -verify -std=c++11 %s 2 3struct X { 4 X(int); 5}; 6struct Y { 7 operator X*(); 8 operator X&(); 9}; 10 11struct S { 12 int &x, *y; // expected-note {{reference member declared here}} \ 13 // expected-note {{pointer member declared here}} 14 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'}} 17 S(int &i) : x(i), y(&i) {} // no-warning: reference parameter 18 S(int *i) : x(*i), y(i) {} // no-warning: pointer parameter 19}; 20 21struct S2 { 22 const X &x; // expected-note {{reference member declared here}} 23 S2(int i) : x(i) {} // expected-warning {{binding reference member 'x' to a temporary}} 24}; 25 26struct S3 { 27 X &x1, *x2; 28 S3(Y y) : x1(y), x2(y) {} // no-warning: conversion operator 29}; 30 31template <typename T> struct S4 { 32 T x; // expected-note {{reference member declared here}} 33 S4(int i) : x(i) {} // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}} 34}; 35 36template struct S4<int>; // no warning from this instantiation 37template struct S4<int&>; // expected-note {{in instantiation}} 38 39struct S5 { 40 const X &x; // expected-note {{here}} 41}; 42S5 s5 = { 0 }; // ok, lifetime-extended 43 44struct S6 { 45 S5 s5; // expected-note {{here}} 46 S6() : s5 { 0 } {} // expected-warning {{binding reference subobject of member 's5' to a temporary}} 47}; 48 49struct S7 : S5 { 50 S7() : S5 { 0 } {} // expected-warning {{binding reference member 'x' to a temporary}} 51}; 52