]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
Vendor import of clang trunk r242221:
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / eh-aggregate-copy-destroy.cpp
1 // Check that in case of copying an array of memcpy-able objects, their
2 // destructors will be called if an exception is thrown.
3 //
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -emit-llvm %s -o - | FileCheck %s
5
6 struct ImplicitCopy {
7   int x;
8   ImplicitCopy() { x = 10; }
9   ~ImplicitCopy() { x = 20; }
10 };
11
12 struct ThrowCopy {
13   ThrowCopy() {}
14   ThrowCopy(const ThrowCopy &) { throw 1; }
15 };
16
17 struct Container {
18   ImplicitCopy b[2];
19   ThrowCopy c;
20 };
21
22 int main () {
23   try {
24     Container c1;
25     // CHECK_LABEL: main
26     // CHECK-NOT: call void @_ZN9ThrowCopyC1ERKS_
27     // CHECK: invoke void @_ZN9ThrowCopyC1ERKS_
28     // CHECK: invoke void @_ZN12ImplicitCopyD1Ev
29     Container c2(c1);
30   }
31   catch (...) {
32     return 1;
33   }
34
35   return 0;
36 }
37