40 lines · cpp
1// Check that in case of copying an array of memcpy-able objects, their2// 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 -std=c++98 -emit-llvm %s -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s5// 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 %s6 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: main27 // CHECK-NOT: call void @_ZN9ThrowCopyC1ERKS_28 // CHECK: invoke void @_ZN9ThrowCopyC1ERKS_29 // CHECK98: invoke void @_ZN12ImplicitCopyD1Ev30 // CHECK11: call void @_ZN12ImplicitCopyD1Ev31 Container c2(c1);32 }33 catch (...) {34 return 1;35 }36 37 return 0;38}39 40