From 252ea8072ded9067b8b7af4c53aced817395c35a Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 30 May 2017 08:29:43 -0600 Subject: [PATCH] Add failing test for const return type #340 --- unittests/compiled_tests.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/unittests/compiled_tests.cpp b/unittests/compiled_tests.cpp index c1716ec9..86dcc092 100644 --- a/unittests/compiled_tests.cpp +++ b/unittests/compiled_tests.cpp @@ -12,6 +12,8 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma GCC diagnostic ignored "-Wparentheses" +// This one is necessary for the const return non-reference test +#pragma GCC diagnostic ignored "-Wignored-qualifiers" #endif @@ -1270,3 +1272,20 @@ TEST_CASE("Test reference member being registered") } +const int add_3(const int &i) +{ + return i + 3; +} + +TEST_CASE("Test returning by const non-reference") +{ + chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser()); + // Note, C++ will not allow us to do this: + // chai.add(chaiscript::fun(&Reference_MyClass::x) , "x"); + chai.add(chaiscript::fun(&add_3), "add_3"); + auto v = chai.eval("add_3(12)"); + CHECK(v == 15); +} + + +