summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/warn-global-constructors.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2010-09-17 15:54:40 +0000
committerdim <dim@FreeBSD.org>2010-09-17 15:54:40 +0000
commit36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch)
tree0bbe07708f7571f8b5291f6d7b96c102b7c99dee /test/SemaCXX/warn-global-constructors.cpp
parentfc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff)
downloadFreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip
FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020 Approved by: rpaulo (mentor)
Diffstat (limited to 'test/SemaCXX/warn-global-constructors.cpp')
-rw-r--r--test/SemaCXX/warn-global-constructors.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-global-constructors.cpp b/test/SemaCXX/warn-global-constructors.cpp
new file mode 100644
index 0000000..107bbe1
--- /dev/null
+++ b/test/SemaCXX/warn-global-constructors.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -fsyntax-only -Wglobal-constructors %s -verify
+
+int opaque_int();
+
+namespace test0 {
+ // These should never require global constructors.
+ int a;
+ int b = 20;
+ float c = 5.0f;
+
+ // This global constructor is avoidable based on initialization order.
+ int d = b; // expected-warning {{global constructor}}
+
+ // These global constructors are unavoidable.
+ int e = opaque_int(); // expected-warning {{global constructor}}
+ int f = b; // expected-warning {{global constructor}}
+}
+
+namespace test1 {
+ struct A { int x; };
+ A a;
+ A b = A();
+ A c = { 10 };
+ A d = { opaque_int() }; // expected-warning {{global constructor}}
+ A e = A(A());
+ A f = A(a); // expected-warning {{global constructor}}
+ A g(a); // expected-warning {{global constructor}}
+ A h((A())); // expected-warning {{global constructor}}
+ A i((A(A()))); // expected-warning {{global constructor}}
+}
+
+namespace test2 {
+ struct A { A(); };
+ A a; // expected-warning {{global constructor}}
+ A b[10]; // expected-warning {{global constructor}}
+ A c[10][10]; // expected-warning {{global constructor}}
+
+ A &d = a;
+ A &e = b[5];
+ A &f = c[5][7];
+}
+
+namespace test3 {
+ struct A { ~A(); };
+ A a; // expected-warning {{global destructor}}
+ A b[10]; // expected-warning {{global destructor}}
+ A c[10][10]; // expected-warning {{global destructor}}
+
+ A &d = a;
+ A &e = b[5];
+ A &f = c[5][7];
+}
+
+namespace test4 {
+ char a[] = "hello";
+ char b[5] = "hello";
+ char c[][5] = { "hello" };
+}
+
+namespace test5 {
+ struct A { A(); };
+
+ void f1() {
+ static A a;
+ }
+ void f2() {
+ static A& a = *new A;
+ }
+}
+
+namespace test6 {
+ struct A { ~A(); };
+
+ void f1() {
+ static A a; // expected-warning {{global destructor}}
+ }
+ void f2() {
+ static A& a = *new A;
+ }
+
+} \ No newline at end of file
OpenPOWER on IntegriCloud