diff --git a/src/test_module.cpp b/src/test_module.cpp index 7c65dc8..9ac98ee 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -51,12 +51,17 @@ class TestMoreDerivedType : public TestDerivedType std::shared_ptr derived_type_factory() { - return std::shared_ptr(new TestDerivedType()); + return std::make_shared(); } std::shared_ptr more_derived_type_factory() { - return std::shared_ptr(new TestMoreDerivedType()); + return std::make_shared(); +} + +std::shared_ptr null_factory() +{ + return std::shared_ptr(); } std::string hello_world() @@ -111,6 +116,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory"); m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory"); + m->add(chaiscript::fun(&null_factory), "null_factory"); m->add(chaiscript::fun(&TestDerivedType::func), "func"); diff --git a/unittests/null_object_access.chai b/unittests/null_object_access.chai new file mode 100644 index 0000000..3ee1c9a --- /dev/null +++ b/unittests/null_object_access.chai @@ -0,0 +1,13 @@ +load_module("test_module") + +auto o = null_factory(); + +try { + o.func(); +} catch (e) { + exit(0); +} + +assert_true(false); + +