Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-dangling-field.cpp
blob578f3df654d298e59c3c7baccc0c891469372147
1 // RUN: %clang_cc1 -fsyntax-only -Wdangling-field -verify -std=c++11 %s
3 struct X {
4 X(int);
5 };
6 struct Y {
7 operator X*();
8 operator X&();
9 };
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
21 struct S2 {
22 const X &x; // expected-note {{reference member declared here}}
23 S2(int i) : x(i) {} // expected-error {{member 'x' binds to a temporary}}
26 struct S3 {
27 X &x1, *x2;
28 S3(Y y) : x1(y), x2(y) {} // no-warning: conversion operator
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'}}
36 template struct S4<int>; // no warning from this instantiation
37 template struct S4<int&>; // expected-note {{in instantiation}}
39 struct S5 {
40 const X &x; // expected-note {{here}}
42 S5 s5 = { 0 }; // ok, lifetime-extended
44 struct S6 {
45 S5 s5; // expected-note {{here}}
46 S6() : s5 { 0 } {} // expected-error {{reference subobject of member 's5' binds to a temporary}}
49 struct S7 : S5 {
50 S7() : S5 { 0 } {} // expected-error {{reference member 'x' binds to a temporary}}
53 struct S8 {
54 int *p;
55 S8(int *a) : p(&a[0]) {}