Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-error=address-of-temporary -verify -std=gnu++11 %s |
| 2 | struct X { |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 3 | X(); |
| 4 | X(int); |
| 5 | X(int, int); |
| 6 | }; |
| 7 | |
Argyrios Kyrtzidis | e72f715 | 2010-11-30 22:57:32 +0000 | [diff] [blame] | 8 | void f0() { (void)&X(); } // expected-warning{{taking the address of a temporary object}} |
| 9 | void f1() { (void)&X(1); } // expected-warning{{taking the address of a temporary object}} |
| 10 | void f2() { (void)&X(1, 2); } // expected-warning{{taking the address of a temporary object}} |
| 11 | void f3() { (void)&(X)1; } // expected-warning{{taking the address of a temporary object}} |
Douglas Gregor | b154fdc | 2010-02-16 21:39:57 +0000 | [diff] [blame] | 12 | |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 13 | |
| 14 | namespace PointerToArrayDecay { |
| 15 | struct Y { |
| 16 | int a[4]; |
| 17 | }; |
Richard Smith | 4be2c36 | 2013-02-02 02:11:36 +0000 | [diff] [blame] | 18 | struct Z { |
| 19 | int n; |
| 20 | ~Z(); |
| 21 | }; |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 22 | |
| 23 | typedef int A[4]; |
Richard Smith | 4be2c36 | 2013-02-02 02:11:36 +0000 | [diff] [blame] | 24 | typedef Z AZ[4]; |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 25 | |
| 26 | template<typename T> void consume(T); |
| 27 | struct S { int *p; }; |
| 28 | |
Richard Smith | 0e3102d | 2018-07-24 00:55:08 +0000 | [diff] [blame] | 29 | void g0() { int *p = Y().a; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 30 | void g1() { int *p = Y{}.a; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 31 | void g2() { int *p = A{}; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 32 | void g3() { int *p = (A){}; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 33 | void g4() { Z *p = AZ{}; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 34 | void g5() { Z *p = &(Z&)(AZ{}[0]); } // expected-warning{{will be destroyed at the end of the full-expression}} |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 35 | |
| 36 | void h0() { consume(Y().a); } |
| 37 | void h1() { consume(Y{}.a); } |
| 38 | void h2() { consume(A{}); } |
| 39 | void h3() { consume((A){}); } |
Richard Smith | 4be2c36 | 2013-02-02 02:11:36 +0000 | [diff] [blame] | 40 | void h4() { consume(AZ{}); } |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 41 | |
Richard Smith | 0e3102d | 2018-07-24 00:55:08 +0000 | [diff] [blame] | 42 | void i0() { S s = { Y().a }; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 43 | void i1() { S s = { Y{}.a }; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 44 | void i2() { S s = { A{} }; } // expected-warning{{will be destroyed at the end of the full-expression}} |
| 45 | void i3() { S s = { (A){} }; } // expected-warning{{will be destroyed at the end of the full-expression}} |
Richard Smith | eb3cad5 | 2012-06-04 22:27:30 +0000 | [diff] [blame] | 46 | |
| 47 | void j0() { (void)S { Y().a }; } |
| 48 | void j1() { (void)S { Y{}.a }; } |
| 49 | void j2() { (void)S { A{} }; } |
| 50 | void j3() { (void)S { (A){} }; } |
| 51 | |
| 52 | void k0() { consume(S { Y().a }); } |
| 53 | void k1() { consume(S { Y{}.a }); } |
| 54 | void k2() { consume(S { A{} }); } |
| 55 | void k3() { consume(S { (A){} }); } |
| 56 | } |