summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-global-constructors.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-08-01 20:20:59 +0000
committerJohn McCall <rjmccall@apple.com>2010-08-01 20:20:59 +0000
commit47e40931c9af037ceae73ecab7db739a34160a0e (patch)
tree58595d6dbe7601fb5dae183533b67eb1ab583a14 /clang/test/SemaCXX/warn-global-constructors.cpp
parent3d4af4e91ed7298137e828969e03caf822ad349d (diff)
downloadbcm5719-llvm-47e40931c9af037ceae73ecab7db739a34160a0e.tar.gz
bcm5719-llvm-47e40931c9af037ceae73ecab7db739a34160a0e.zip
Make a first pass at implementing -Wglobal-constructors. I'm worried that this
will end up bizarrely mirroring CGExprConstant, but that might be the hazard of this feature. llvm-svn: 109984
Diffstat (limited to 'clang/test/SemaCXX/warn-global-constructors.cpp')
-rw-r--r--clang/test/SemaCXX/warn-global-constructors.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-global-constructors.cpp b/clang/test/SemaCXX/warn-global-constructors.cpp
new file mode 100644
index 00000000000..6d0709c5b79
--- /dev/null
+++ b/clang/test/SemaCXX/warn-global-constructors.cpp
@@ -0,0 +1,39 @@
+// 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}}
+}
+
+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}}
+}
+
+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}}
+}
OpenPOWER on IntegriCloud