1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wno-error=address-of-temporary -verify -std=gnu++11 %s 2*f4a2713aSLionel Sambuc struct X { 3*f4a2713aSLionel Sambuc X(); 4*f4a2713aSLionel Sambuc X(int); 5*f4a2713aSLionel Sambuc X(int, int); 6*f4a2713aSLionel Sambuc }; 7*f4a2713aSLionel Sambuc f0()8*f4a2713aSLionel Sambucvoid f0() { (void)&X(); } // expected-warning{{taking the address of a temporary object}} f1()9*f4a2713aSLionel Sambucvoid f1() { (void)&X(1); } // expected-warning{{taking the address of a temporary object}} f2()10*f4a2713aSLionel Sambucvoid f2() { (void)&X(1, 2); } // expected-warning{{taking the address of a temporary object}} f3()11*f4a2713aSLionel Sambucvoid f3() { (void)&(X)1; } // expected-warning{{taking the address of a temporary object}} 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc namespace PointerToArrayDecay { 15*f4a2713aSLionel Sambuc struct Y { 16*f4a2713aSLionel Sambuc int a[4]; 17*f4a2713aSLionel Sambuc }; 18*f4a2713aSLionel Sambuc struct Z { 19*f4a2713aSLionel Sambuc int n; 20*f4a2713aSLionel Sambuc ~Z(); 21*f4a2713aSLionel Sambuc }; 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc typedef int A[4]; 24*f4a2713aSLionel Sambuc typedef Z AZ[4]; 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc template<typename T> void consume(T); 27*f4a2713aSLionel Sambuc struct S { int *p; }; 28*f4a2713aSLionel Sambuc g0()29*f4a2713aSLionel Sambuc void g0() { int *p = Y().a; } // expected-warning{{pointer is initialized by a temporary array}} g1()30*f4a2713aSLionel Sambuc void g1() { int *p = Y{}.a; } // expected-warning{{pointer is initialized by a temporary array}} g2()31*f4a2713aSLionel Sambuc void g2() { int *p = A{}; } // expected-warning{{pointer is initialized by a temporary array}} g3()32*f4a2713aSLionel Sambuc void g3() { int *p = (A){}; } // expected-warning{{pointer is initialized by a temporary array}} g4()33*f4a2713aSLionel Sambuc void g4() { Z *p = AZ{}; } // expected-warning{{pointer is initialized by a temporary array}} 34*f4a2713aSLionel Sambuc h0()35*f4a2713aSLionel Sambuc void h0() { consume(Y().a); } h1()36*f4a2713aSLionel Sambuc void h1() { consume(Y{}.a); } h2()37*f4a2713aSLionel Sambuc void h2() { consume(A{}); } h3()38*f4a2713aSLionel Sambuc void h3() { consume((A){}); } h4()39*f4a2713aSLionel Sambuc void h4() { consume(AZ{}); } 40*f4a2713aSLionel Sambuc i0()41*f4a2713aSLionel Sambuc void i0() { S s = { Y().a }; } // expected-warning{{pointer is initialized by a temporary array}} i1()42*f4a2713aSLionel Sambuc void i1() { S s = { Y{}.a }; } // expected-warning{{pointer is initialized by a temporary array}} i2()43*f4a2713aSLionel Sambuc void i2() { S s = { A{} }; } // expected-warning{{pointer is initialized by a temporary array}} i3()44*f4a2713aSLionel Sambuc void i3() { S s = { (A){} }; } // expected-warning{{pointer is initialized by a temporary array}} 45*f4a2713aSLionel Sambuc j0()46*f4a2713aSLionel Sambuc void j0() { (void)S { Y().a }; } j1()47*f4a2713aSLionel Sambuc void j1() { (void)S { Y{}.a }; } j2()48*f4a2713aSLionel Sambuc void j2() { (void)S { A{} }; } j3()49*f4a2713aSLionel Sambuc void j3() { (void)S { (A){} }; } 50*f4a2713aSLionel Sambuc k0()51*f4a2713aSLionel Sambuc void k0() { consume(S { Y().a }); } k1()52*f4a2713aSLionel Sambuc void k1() { consume(S { Y{}.a }); } k2()53*f4a2713aSLionel Sambuc void k2() { consume(S { A{} }); } k3()54*f4a2713aSLionel Sambuc void k3() { consume(S { (A){} }); } 55*f4a2713aSLionel Sambuc } 56