From 5262b1e541c8f67e249074eef5e0567e6603ccd9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 19 Jan 2022 18:54:42 +0100 Subject: Add test case for C++ exception handling --- testsuite/tests/rts/T11829.hs | 5 +++++ testsuite/tests/rts/T11829.stderr | 1 + testsuite/tests/rts/T11829.stdout | 1 + testsuite/tests/rts/T11829_c.cpp | 19 +++++++++++++++++++ testsuite/tests/rts/all.T | 5 +++++ 5 files changed, 31 insertions(+) create mode 100644 testsuite/tests/rts/T11829.hs create mode 100644 testsuite/tests/rts/T11829.stderr create mode 100644 testsuite/tests/rts/T11829.stdout create mode 100644 testsuite/tests/rts/T11829_c.cpp (limited to 'testsuite/tests/rts') diff --git a/testsuite/tests/rts/T11829.hs b/testsuite/tests/rts/T11829.hs new file mode 100644 index 0000000000..5983dfb226 --- /dev/null +++ b/testsuite/tests/rts/T11829.hs @@ -0,0 +1,5 @@ +module Main where +import Foreign.C.Types +foreign import ccall func :: IO CInt +main :: IO () +main = print =<< func diff --git a/testsuite/tests/rts/T11829.stderr b/testsuite/tests/rts/T11829.stderr new file mode 100644 index 0000000000..0527e6bd2d --- /dev/null +++ b/testsuite/tests/rts/T11829.stderr @@ -0,0 +1 @@ +This is a test diff --git a/testsuite/tests/rts/T11829.stdout b/testsuite/tests/rts/T11829.stdout new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/testsuite/tests/rts/T11829.stdout @@ -0,0 +1 @@ +42 diff --git a/testsuite/tests/rts/T11829_c.cpp b/testsuite/tests/rts/T11829_c.cpp new file mode 100644 index 0000000000..959851ad74 --- /dev/null +++ b/testsuite/tests/rts/T11829_c.cpp @@ -0,0 +1,19 @@ +#include +#include +extern "C" { + +int func() { + try { + throw std::runtime_error("This is a test"); + } catch(const std::runtime_error &c) { + std::cerr << c.what() << std::endl; + return 42; + } catch(...) { + std::cerr << "Catch-all must not fire!" << std::endl; + return -1; + } + std::cerr << "Control must not reach past try-catch block!" << std::endl; + return -2; +} + +} diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T index 7adb936b08..f2098f4122 100644 --- a/testsuite/tests/rts/all.T +++ b/testsuite/tests/rts/all.T @@ -470,6 +470,11 @@ test('keep-cafs', ], makefile_test, ['KeepCafs']) +# Test proper functioning of C++ exceptions within a C++ program. +# On darwin, this requires -fcompact-unwind. +# When -fcompact-unwind becomes default, generalize test to all platforms. +test('T11829', unless(opsys('darwin'), skip), compile_and_run, ['T11829_c.cpp -lstdc++ -fcompact-unwind']) + test('T16514', unless(opsys('mingw32'), skip), compile_and_run, ['T16514_c.cpp -lstdc++']) test('test-zeroongc', extra_run_opts('-DZ'), compile_and_run, ['-debug']) -- cgit v1.2.1