blob: c407e407bb9f0408d494875785de9239d746f0b0 [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}}
25}
26
27namespace test2 {
28 struct A { A(); };
29 A a; // expected-warning {{global constructor}}
30 A b[10]; // expected-warning {{global constructor}}
31 A c[10][10]; // expected-warning {{global constructor}}
John McCallb4b9b152010-08-01 21:51:45 +000032
33 // FIXME: false positives!
34 A &d = a; // expected-warning {{global constructor}}
35 A &e = b[5]; // expected-warning {{global constructor}}
36 A &f = c[5][7]; // expected-warning {{global constructor}}
John McCall626e96e2010-08-01 20:20:59 +000037}
38
39namespace test3 {
40 struct A { ~A(); };
41 A a; // expected-warning {{global destructor}}
42 A b[10]; // expected-warning {{global destructor}}
43 A c[10][10]; // expected-warning {{global destructor}}
John McCallb4b9b152010-08-01 21:51:45 +000044
45 // FIXME: false positives!
46 A &d = a; // expected-warning {{global constructor}}
47 A &e = b[5]; // expected-warning {{global constructor}}
48 A &f = c[5][7]; // expected-warning {{global constructor}}
49}
50
51namespace test4 {
52 char a[] = "hello";
53 char b[5] = "hello";
54 char c[][5] = { "hello" };
John McCall626e96e2010-08-01 20:20:59 +000055}