diff --git a/doc/manual.md b/doc/manual.md index f140f5e30c97..842c3f3dc459 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -5169,7 +5169,7 @@ It is possible to raise/catch imported C++ exceptions. Types imported using `importcpp` can be raised or caught. Exceptions are raised by value and caught by reference. Example: - ```nim test = "nim cpp -r $1" + ```nim type CStdException {.importcpp: "std::exception", header: "", inheritable.} = object ## does not inherit from `RootObj`, so we use `inheritable` instead @@ -5187,7 +5187,7 @@ caught by reference. Example: except CStdException as e: doAssert e is CStdException b = e.what() - doAssert $b == "foo2", $b + doAssert $b == "foo2" try: raise initStdException() except CStdException: discard diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 4ee0f03697fe..2d1554b1cafb 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -109,7 +109,9 @@ pkg "netty" pkg "nico", allowFailure = true pkg "nicy", "nim c -r src/nicy.nim" when defined(osx): - pkg "nigui", "nim c --clibdir:/usr/local/lib -o:niguii -r src/nigui.nim" + # gives "could not load: libgtk-3.0.dylib" on macos 13 + # just test compiling instead of running + pkg "nigui", "nim c -o:niguii src/nigui.nim" else: pkg "nigui", "nim c -o:niguii -r src/nigui.nim" pkg "nimcrypto", "nim r --path:. tests/testall.nim" # `--path:.` workaround needed, see D20210308T165435 diff --git a/tests/cpp/temitlist.nim b/tests/cpp/temitlist.nim index 9170be079643..c4d6ed9e794b 100644 --- a/tests/cpp/temitlist.nim +++ b/tests/cpp/temitlist.nim @@ -3,7 +3,7 @@ discard """ output: ''' 6.0 0''' -disabled: "windows" # pending bug #18011 +#disabled: "windows" # pending bug #18011 """ # bug #4730 diff --git a/tests/cpp/tempty_generic_obj.nim b/tests/cpp/tempty_generic_obj.nim index 6125190b4f0e..f1e273cc54b3 100644 --- a/tests/cpp/tempty_generic_obj.nim +++ b/tests/cpp/tempty_generic_obj.nim @@ -3,7 +3,7 @@ discard """ output: ''' int float''' -disabled: "windows" # pending bug #18011 +#disabled: "windows" # pending bug #18011 """ import typetraits diff --git a/tests/cpp/tmanual_exception.nim b/tests/cpp/tmanual_exception.nim new file mode 100644 index 000000000000..a91ccffe4cb2 --- /dev/null +++ b/tests/cpp/tmanual_exception.nim @@ -0,0 +1,38 @@ +discard """ + # doesn't work on macos 13 seemingly due to libc++ linking issue https://stackoverflow.com/a/77375947 + disabled: osx + targets: cpp +""" + +# manual example + +type + CStdException {.importcpp: "std::exception", header: "", inheritable.} = object + ## does not inherit from `RootObj`, so we use `inheritable` instead + CRuntimeError {.requiresInit, importcpp: "std::runtime_error", header: "".} = object of CStdException + ## `CRuntimeError` has no default constructor => `requiresInit` +proc what(s: CStdException): cstring {.importcpp: "((char *)#.what())".} +proc initRuntimeError(a: cstring): CRuntimeError {.importcpp: "std::runtime_error(@)", constructor.} +proc initStdException(): CStdException {.importcpp: "std::exception()", constructor.} + +proc fn() = + let a = initRuntimeError("foo") + doAssert $a.what == "foo" + var b: cstring + try: raise initRuntimeError("foo2") + except CStdException as e: + doAssert e is CStdException + b = e.what() + doAssert $b == "foo2" + + try: raise initStdException() + except CStdException: discard + + try: raise initRuntimeError("foo3") + except CRuntimeError as e: + b = e.what() + except CStdException: + doAssert false + doAssert $b == "foo3" + +fn() diff --git a/tests/exception/tcpp_imported_exc.nim b/tests/exception/tcpp_imported_exc.nim index 55a58440ffb5..0c7846956bb7 100644 --- a/tests/exception/tcpp_imported_exc.nim +++ b/tests/exception/tcpp_imported_exc.nim @@ -14,7 +14,8 @@ finally 2 expected cpp exception caught ''' -disabled: "windows" # pending bug #18011 +# doesn't work on macos 13 seemingly due to libc++ linking issue https://stackoverflow.com/a/77375947 +disabled: osx """ type