blob: 5eef1c5521c4d32f7a134608efe1836682f972fd [file] [log] [blame]
Richard Smith36d02af2012-06-04 22:27:30 +00001// RUN: %clang_cc1 -fsyntax-only -Wno-error=address-of-temporary -verify -std=gnu++11 %s
2struct X {
Douglas Gregore873fb72010-02-16 21:39:57 +00003 X();
4 X(int);
5 X(int, int);
6};
7
Argyrios Kyrtzidis26e10be2010-11-30 22:57:32 +00008void f0() { (void)&X(); } // expected-warning{{taking the address of a temporary object}}
9void f1() { (void)&X(1); } // expected-warning{{taking the address of a temporary object}}
10void f2() { (void)&X(1, 2); } // expected-warning{{taking the address of a temporary object}}
11void f3() { (void)&(X)1; } // expected-warning{{taking the address of a temporary object}}
Douglas Gregore873fb72010-02-16 21:39:57 +000012
Richard Smith36d02af2012-06-04 22:27:30 +000013
14namespace PointerToArrayDecay {
15 struct Y {
16 int a[4];
17 };
Richard Smith821b93e2013-02-02 02:11:36 +000018 struct Z {
19 int n;
20 ~Z();
21 };
Richard Smith36d02af2012-06-04 22:27:30 +000022
23 typedef int A[4];
Richard Smith821b93e2013-02-02 02:11:36 +000024 typedef Z AZ[4];
Richard Smith36d02af2012-06-04 22:27:30 +000025
26 template<typename T> void consume(T);
27 struct S { int *p; };
28
29 void g0() { int *p = Y().a; } // expected-warning{{pointer is initialized by a temporary array}}
30 void g1() { int *p = Y{}.a; } // expected-warning{{pointer is initialized by a temporary array}}
31 void g2() { int *p = A{}; } // expected-warning{{pointer is initialized by a temporary array}}
32 void g3() { int *p = (A){}; } // expected-warning{{pointer is initialized by a temporary array}}
Richard Smith821b93e2013-02-02 02:11:36 +000033 void g4() { Z *p = AZ{}; } // expected-warning{{pointer is initialized by a temporary array}}
Richard Smith36d02af2012-06-04 22:27:30 +000034
35 void h0() { consume(Y().a); }
36 void h1() { consume(Y{}.a); }
37 void h2() { consume(A{}); }
38 void h3() { consume((A){}); }
Richard Smith821b93e2013-02-02 02:11:36 +000039 void h4() { consume(AZ{}); }
Richard Smith36d02af2012-06-04 22:27:30 +000040
41 void i0() { S s = { Y().a }; } // expected-warning{{pointer is initialized by a temporary array}}
42 void i1() { S s = { Y{}.a }; } // expected-warning{{pointer is initialized by a temporary array}}
43 void i2() { S s = { A{} }; } // expected-warning{{pointer is initialized by a temporary array}}
44 void i3() { S s = { (A){} }; } // expected-warning{{pointer is initialized by a temporary array}}
45
46 void j0() { (void)S { Y().a }; }
47 void j1() { (void)S { Y{}.a }; }
48 void j2() { (void)S { A{} }; }
49 void j3() { (void)S { (A){} }; }
50
51 void k0() { consume(S { Y().a }); }
52 void k1() { consume(S { Y{}.a }); }
53 void k2() { consume(S { A{} }); }
54 void k3() { consume(S { (A){} }); }
55}