1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s -verify
6 // These should never require global constructors.
11 // This global constructor is avoidable based on initialization order.
12 int d
= b
; // expected-warning {{global constructor}}
14 // These global constructors are unavoidable.
15 int e
= opaque_int(); // expected-warning {{global constructor}}
16 int f
= b
; // expected-warning {{global constructor}}
24 A d
= { opaque_int() }; // expected-warning {{global constructor}}
26 A f
= A(a
); // expected-warning {{global constructor}}
27 A
g(a
); // expected-warning {{global constructor}}
29 A
i((A(A()))); // elided
34 A a
; // expected-warning {{global constructor}}
35 A b
[10]; // expected-warning {{global constructor}}
36 A c
[10][10]; // expected-warning {{global constructor}}
45 A a
; // expected-warning {{global destructor}}
46 A b
[10]; // expected-warning {{global destructor}}
47 A c
[10][10]; // expected-warning {{global destructor}}
57 char c
[][6] = { "hello" };
85 Foo(int x1
) : x(x1
) {}
99 namespace referencemember
{
100 struct A
{ int &a
; };
106 struct A
{ ~A() = default; };
110 struct C
: B
{ ~C() = default; };
111 C c
; // expected-warning {{global destructor}}
125 // No warning is expected. This used to crash.
126 void *array_storage
[1];
127 const int &global_reference
= *(int *)array_storage
;
130 namespace bitfields
{
131 struct HasUnnamedBitfield
{
136 constexpr HasUnnamedBitfield() : a(), b() {}
137 constexpr HasUnnamedBitfield(unsigned a
, unsigned b
) : a(a
), b(b
) {}
138 explicit HasUnnamedBitfield(unsigned a
) {}
141 const HasUnnamedBitfield zeroConst
{};
142 HasUnnamedBitfield zeroMutable
{};
143 const HasUnnamedBitfield explicitConst
{1, 2};
144 HasUnnamedBitfield explicitMutable
{1, 2};
145 const HasUnnamedBitfield nonConstexprConst
{1}; // expected-warning {{global constructor}}
146 HasUnnamedBitfield nonConstexprMutable
{1}; // expected-warning {{global constructor}}