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 } 26 27 namespace 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}} 32 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}} 37 } 38 39 namespace 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}} 44 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 51 namespace test4 { 52 char a[] = "hello"; 53 char b[5] = "hello"; 54 char c[][5] = { "hello" }; 55 } 56