summaryrefslogtreecommitdiffstats
path: root/libcxxabi/test/test_guard.cpp
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2011-05-24 22:01:16 +0000
committerHoward Hinnant <hhinnant@apple.com>2011-05-24 22:01:16 +0000
commit4a88971ac15e5ac5a4560552838acb5e0bbce3da (patch)
treed7b2e774efa96719bb75bc9dd19cc0fc9b03aca4 /libcxxabi/test/test_guard.cpp
parent82fe5f43d91f9d3e81b4844c59d92d2632f03d6f (diff)
downloadbcm5719-llvm-4a88971ac15e5ac5a4560552838acb5e0bbce3da.tar.gz
bcm5719-llvm-4a88971ac15e5ac5a4560552838acb5e0bbce3da.zip
Introduce cxa_virtual.cpp and cxa_guard.cpp. Contributed by Nick Lewycky, Howard Hinnant and John McCall
llvm-svn: 132009
Diffstat (limited to 'libcxxabi/test/test_guard.cpp')
-rw-r--r--libcxxabi/test/test_guard.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/libcxxabi/test/test_guard.cpp b/libcxxabi/test/test_guard.cpp
new file mode 100644
index 00000000000..c69b8e73077
--- /dev/null
+++ b/libcxxabi/test/test_guard.cpp
@@ -0,0 +1,59 @@
+//===----------------------------- test_guard.cpp -------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "cxxabi.h"
+
+#include <cassert>
+
+namespace test1 {
+ static int run_count = 0;
+ int increment() {
+ ++run_count;
+ return 0;
+ }
+ void helper() {
+ static int a = increment();
+ }
+ void test() {
+ static int a = increment();
+ assert(run_count == 1);
+ static int b = increment();
+ assert(run_count == 2);
+ helper();
+ assert(run_count == 3);
+ helper();
+ assert(run_count == 3);
+ }
+}
+
+namespace test2 {
+ static int run_count = 0;
+ int increment() {
+ ++run_count;
+ throw 0;
+ }
+ void helper() {
+ try {
+ static int a = increment();
+ assert(0);
+ } catch (...) {}
+ }
+ void test() {
+ helper();
+ assert(run_count == 1);
+ helper();
+ assert(run_count == 2);
+ }
+}
+
+int main()
+{
+ test1::test();
+ test2::test();
+}
OpenPOWER on IntegriCloud