1 // RUN: %clang_cc1 -fsyntax-only -Wglobal-constructors %s -verify 2 3 int opaque_int(); 4 5 namespace 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 19 namespace 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 A e = A(A()); 26 A f = A(a); // expected-warning {{global constructor}} 27 A g(a); // expected-warning {{global constructor}} 28 A h((A())); // expected-warning {{global constructor}} 29 A i((A(A()))); // expected-warning {{global constructor}} 30 } 31 32 namespace 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}} 37 38 A &d = a; 39 A &e = b[5]; 40 A &f = c[5][7]; 41 } 42 43 namespace 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}} 48 49 A &d = a; 50 A &e = b[5]; 51 A &f = c[5][7]; 52 } 53 54 namespace test4 { 55 char a[] = "hello"; 56 char b[5] = "hello"; 57 char c[][5] = { "hello" }; 58 } 59