blob: 6330958df703e8b9006880d7bd65b0b1742d28a3 [file] [log] [blame]
John McCall626e96e2010-08-01 20:20:59 +00001// RUN: %clang_cc1 -fsyntax-only -Wglobal-constructors %s -verify
2
3int opaque_int();
4
5namespace test0 {
6 // These should never require global constructors.
7 int a;
8 int b = 20;
9 float c = 5.0f;
10
11 // This global constructor is avoidable based on initialization order.
12 int d = b; // expected-warning {{global constructor}}
13
14 // These global constructors are unavoidable.
15 int e = opaque_int(); // expected-warning {{global constructor}}
16 int f = b; // expected-warning {{global constructor}}
17}
18
19namespace test1 {
20 struct A { int x; };
21 A a;
22 A b = A();
23 A c = { 10 };
24 A d = { opaque_int() }; // expected-warning {{global constructor}}
John McCall4204f072010-08-02 21:13:48 +000025 A e = A(A());
26 A f = A(a); // expected-warning {{global constructor}}
27 A g(a); // expected-warning {{global constructor}}
John McCall558d2ab2010-09-15 10:14:12 +000028 A h((A())); // elided
29 A i((A(A()))); // elided
John McCall626e96e2010-08-01 20:20:59 +000030}
31
32namespace test2 {
33 struct A { A(); };
34 A a; // expected-warning {{global constructor}}
35 A b[10]; // expected-warning {{global constructor}}
36 A c[10][10]; // expected-warning {{global constructor}}
John McCallb4b9b152010-08-01 21:51:45 +000037
John McCall4204f072010-08-02 21:13:48 +000038 A &d = a;
39 A &e = b[5];
40 A &f = c[5][7];
John McCall626e96e2010-08-01 20:20:59 +000041}
42
43namespace test3 {
44 struct A { ~A(); };
45 A a; // expected-warning {{global destructor}}
46 A b[10]; // expected-warning {{global destructor}}
47 A c[10][10]; // expected-warning {{global destructor}}
John McCallb4b9b152010-08-01 21:51:45 +000048
John McCall4204f072010-08-02 21:13:48 +000049 A &d = a;
50 A &e = b[5];
51 A &f = c[5][7];
John McCallb4b9b152010-08-01 21:51:45 +000052}
53
54namespace test4 {
55 char a[] = "hello";
Eli Friedmanbc34b1d2011-04-11 00:23:45 +000056 char b[6] = "hello";
57 char c[][6] = { "hello" };
John McCall626e96e2010-08-01 20:20:59 +000058}
Anders Carlsson4938f232010-09-03 01:11:38 +000059
60namespace test5 {
61 struct A { A(); };
62
63 void f1() {
64 static A a;
65 }
66 void f2() {
67 static A& a = *new A;
68 }
69}
70
71namespace test6 {
72 struct A { ~A(); };
73
74 void f1() {
John McCallae792222010-09-18 05:25:11 +000075 static A a;
Anders Carlsson4938f232010-09-03 01:11:38 +000076 }
77 void f2() {
78 static A& a = *new A;
79 }
Sebastian Redl36281c62010-09-08 04:46:19 +000080}
Anders Carlsson4938f232010-09-03 01:11:38 +000081
Sebastian Redl36281c62010-09-08 04:46:19 +000082namespace pr8095 {
83 struct Foo {
84 int x;
85 Foo(int x1) : x(x1) {}
86 };
John McCallae792222010-09-18 05:25:11 +000087 void foo() {
Sebastian Redl36281c62010-09-08 04:46:19 +000088 static Foo a(0);
89 }
John McCallae792222010-09-18 05:25:11 +000090
91 struct Bar {
92 ~Bar();
93 };
94 void bar() {
95 static Bar b;
96 }
Sebastian Redl36281c62010-09-08 04:46:19 +000097}