blob: 9f0f36c875618050a5c2ff776cd7726e12302f2b [file] [log] [blame]
Alexey Bataev5d49b832015-07-08 07:31:02 +00001// Check that in case of copying an array of memcpy-able objects, their
2// destructors will be called if an exception is thrown.
3//
Charles Lifad02412017-01-09 18:24:16 +00004// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -std=c++98 -emit-llvm %s -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
5// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -std=c++11 -emit-llvm %s -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
Alexey Bataev5d49b832015-07-08 07:31:02 +00006
7struct ImplicitCopy {
8 int x;
9 ImplicitCopy() { x = 10; }
10 ~ImplicitCopy() { x = 20; }
11};
12
13struct ThrowCopy {
14 ThrowCopy() {}
15 ThrowCopy(const ThrowCopy &) { throw 1; }
16};
17
18struct Container {
19 ImplicitCopy b[2];
20 ThrowCopy c;
21};
22
23int main () {
24 try {
25 Container c1;
26 // CHECK_LABEL: main
27 // CHECK-NOT: call void @_ZN9ThrowCopyC1ERKS_
28 // CHECK: invoke void @_ZN9ThrowCopyC1ERKS_
Charles Lifad02412017-01-09 18:24:16 +000029 // CHECK98: invoke void @_ZN12ImplicitCopyD1Ev
30 // CHECK11: call void @_ZN12ImplicitCopyD1Ev
Alexey Bataev5d49b832015-07-08 07:31:02 +000031 Container c2(c1);
32 }
33 catch (...) {
34 return 1;
35 }
36
37 return 0;
38}
39