Home | History | Annotate | Download | only in SemaCXX
      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}}
     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 
     21 struct 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 
     26 struct S3 {
     27   X &x1, *x2;
     28   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}}
     33   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}}
     46   S6() : s5 { 0 } {} // expected-warning {{binding reference subobject of member 's5' to a temporary}}
     47 };
     48 
     49 struct S7 : S5 {
     50   S7() : S5 { 0 } {} // expected-warning {{binding reference member 'x' to a temporary}}
     51 };
     52