diff options
author | Robert Hensing <robert@roberthensing.nl> | 2022-01-19 18:54:42 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2022-03-04 14:04:20 -0500 |
commit | ddf209f3301cd8120c41f5f3e1d71fac2538180b (patch) | |
tree | 0ea9d21ee186606c41908348373837fce4b6e8a4 | |
parent | 1831d9ebd962d9f664686db2dd06a0364484f8bf (diff) | |
download | haskell-ddf209f3301cd8120c41f5f3e1d71fac2538180b.tar.gz |
Add test case for C++ exception handling
(cherry picked from commit 2133ab185fad97f16865bfec47db400daa9f475d)
-rw-r--r-- | testsuite/tests/rts/T11829.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/rts/T11829.stderr | 1 | ||||
-rw-r--r-- | testsuite/tests/rts/T11829.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/rts/T11829_c.cpp | 19 | ||||
-rw-r--r-- | testsuite/tests/rts/all.T | 5 |
5 files changed, 31 insertions, 0 deletions
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 <iostream> +#include <exception> +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 97e99ebeec..9f70aa0b5e 100644 --- a/testsuite/tests/rts/all.T +++ b/testsuite/tests/rts/all.T @@ -422,6 +422,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']) |