diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaCXX/warn-global-constructors.cpp | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaCXX/warn-global-constructors.cpp')
-rw-r--r-- | clang/test/SemaCXX/warn-global-constructors.cpp | 97 |
1 files changed, 97 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 0000000..6330958 --- /dev/null +++ b/clang/test/SemaCXX/warn-global-constructors.cpp @@ -0,0 +1,97 @@ +// 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())); // elided + A i((A(A()))); // elided +} + +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[6] = "hello"; + char c[][6] = { "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; + } + void f2() { + static A& a = *new A; + } +} + +namespace pr8095 { + struct Foo { + int x; + Foo(int x1) : x(x1) {} + }; + void foo() { + static Foo a(0); + } + + struct Bar { + ~Bar(); + }; + void bar() { + static Bar b; + } +} |