[llvm-commits] [test-suite] r121987 - /test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Dec 16 10:20:44 PST 2010


Author: fjahanian
Date: Thu Dec 16 12:20:44 2010
New Revision: 121987

URL: http://llvm.org/viewvc/llvm-project?rev=121987&view=rev
Log:
Another useful test case for imported c++ objects
into blocks. // rdar://8768050


Added:
    test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp

Added: test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp?rev=121987&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp (added)
+++ test-suite/trunk/SingleSource/UnitTests/block-copied-in-cxxobj-1.cpp Thu Dec 16 12:20:44 2010
@@ -0,0 +1,54 @@
+#if defined(__BLOCKS__) && defined(__clang__)
+// rdar://8768050
+#include <stdio.h>
+#include <stdlib.h>
+#include <Block.h>
+#include <auto_zone.h>
+
+static int expected_dtors;
+
+class A {
+private:
+	void *p;
+public:
+	A() throw() {
+		printf("%u\t%p\t%s\n", __LINE__, this, __PRETTY_FUNCTION__);
+	}
+	A(const A &a) throw() : p(a.p) {
+		printf("%u\t%p\t%p\t%s\n", __LINE__, this, &a, __PRETTY_FUNCTION__);
+	}
+	A &operator =(const A &a) throw() {
+		printf("%u\t%p\t%p\t%s\n", __LINE__, this, &a, __PRETTY_FUNCTION__);
+		return *this;
+	}
+	~A() throw() {
+		printf("%u\t%p\t%s\n", __LINE__, this, __PRETTY_FUNCTION__);
+		expected_dtors--;
+		if (expected_dtors < 0) {
+			abort();
+		}
+	}
+	void m() const throw() {
+		printf("%u\t%p\t%s\n", __LINE__, this, __PRETTY_FUNCTION__);
+	}
+};
+
+#endif
+
+int
+main(void)
+{
+#if defined(__BLOCKS__) && defined(__clang__)
+	A a;
+
+	void (^b)(void) = Block_copy(^{
+		a.m();
+	});
+
+	b();
+
+        expected_dtors = 3;
+	Block_release(b);
+#endif
+	return 0;
+}





More information about the llvm-commits mailing list