From 61d610bb70dfafb5b043b472b8afca53bc5d1171 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Thu, 21 Sep 2017 19:24:21 -0400 Subject: [PATCH] make minor changes for XCode and Visual Studio Warning Level 4. --- single/sol/sol.hpp | 33 +++++++------ sol.hpp | 6 ++- sol/compatibility/compat-5.3.c | 4 +- sol/container_traits.hpp | 2 +- sol/reference.hpp | 2 +- sol/stack_check.hpp | 6 +-- sol/stack_get.hpp | 10 ++-- tests/test_container_semantics.cpp | 79 ++++++++++++++---------------- tests/test_functions.cpp | 1 - tests/test_inheritance.cpp | 1 + tests/test_storage.cpp | 17 ++++++- tests/test_tables.cpp | 6 +-- tests/tests.cpp | 4 +- 13 files changed, 93 insertions(+), 78 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 9182c075..27716697 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-09-16 18:18:13.277753 UTC -// This header was generated with sol v2.18.3 (revision 2aecb11) +// Generated 2017-09-21 23:23:58.410071 UTC +// This header was generated with sol v2.18.3 (revision 76d7195) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -50,12 +50,15 @@ #if __GNUC__ > 6 #pragma GCC diagnostic ignored "-Wnoexcept-type" #endif +#elif defined __clang__ #elif defined _MSC_VER #pragma warning( push ) #pragma warning( disable : 4324 ) // structure was padded due to alignment specifier #pragma warning( disable : 4503 ) // decorated name horse shit #pragma warning( disable : 4702 ) // unreachable code -#endif // g++ +#pragma warning( disable: 4127 ) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk +#pragma warning( disable: 4505 ) // some other nonsense warning +#endif // clang++ vs. g++ vs. VC++ // beginning of sol/forward.hpp @@ -2496,7 +2499,7 @@ static int compat53_skipBOM (compat53_LoadF *lf) { do { c = getc(lf->f); if (c == EOF || c != *(const unsigned char *)p++) return c; - lf->buff[lf->n++] = c; /* to be read by the parser */ + lf->buff[lf->n++] = (char)c; /* to be read by the parser */ } while (*p != '\0'); lf->n = 0; /* prefix matched; discard it */ return getc(lf->f); /* return next character */ @@ -2571,7 +2574,7 @@ COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char compat53_skipcomment(&lf, &c); /* re-read initial portion */ } if (c != EOF) - lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ + lf.buff[lf.n++] = (char)(c); /* 'c' is the first character of the stream */ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode); readstatus = ferror(lf.f); if (filename) fclose(lf.f); /* close file (even in case of errors) */ @@ -6180,7 +6183,7 @@ namespace sol { ref = LUA_NOREF; return; } - if (r.get_type() == type::nil) { + if (r.get_type() == type::lua_nil) { ref = LUA_REFNIL; return; } @@ -7334,7 +7337,7 @@ namespace stack { return true; } type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { + if (t == type::table || t == type::none || t == type::lua_nil) { lua_pop(L, 1); return true; } @@ -7353,7 +7356,7 @@ namespace stack { static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { tracking.use(1); type t = type_of(L, index); - if (t == type::table || t == type::none || t == type::nil || t == type::userdata) { + if (t == type::table || t == type::none || t == type::lua_nil || t == type::userdata) { return true; } handler(L, index, type::table, t, "value cannot not have a valid environment"); @@ -7370,7 +7373,7 @@ namespace stack { return true; } type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { + if (t == type::table || t == type::none || t == type::lua_nil) { lua_pop(L, 1); return true; } @@ -7669,7 +7672,7 @@ namespace stack { tracking.use(1); int index = lua_absindex(L, relindex); - T arr; + T arr{}; std::size_t idx = 0; #if SOL_LUA_VERSION >= 503 // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3 @@ -7701,8 +7704,8 @@ namespace stack { for (int vi = 0; vi < lua_size::value; ++vi) { lua_pushinteger(L, i); lua_gettable(L, index); - type t = type_of(L, -1); - isnil = t == type::lua_nil; + type vt = type_of(L, -1); + isnil = vt == type::lua_nil; if (isnil) { if (i == 0) { break; @@ -8299,7 +8302,7 @@ namespace stack { typedef std::variant_size V_size; typedef std::integral_constant V_is_empty; - static V get_empty(std::true_type, lua_State* L, int index, record& tracking) { + static V get_empty(std::true_type, lua_State*, int, record&) { return V(); } @@ -8308,7 +8311,7 @@ namespace stack { // This should never be reached... // please check your code and understand what you did to bring yourself here std::abort(); - return V(std::in_place_index<0>, stack::get(L, index)); + return V(std::in_place_index<0>, stack::get(L, index, tracking)); } static V get_one(std::integral_constant, lua_State* L, int index, record& tracking) { @@ -14851,7 +14854,7 @@ namespace sol { static int set(lua_State* L) { stack_object value = stack_object(L, raw_index(3)); - if (type_of(L, 3) == type::nil) { + if (type_of(L, 3) == type::lua_nil) { return erase(L); } auto& self = get_src(L); diff --git a/sol.hpp b/sol.hpp index f428c7f4..405b7ceb 100644 --- a/sol.hpp +++ b/sol.hpp @@ -40,12 +40,16 @@ #if __GNUC__ > 6 #pragma GCC diagnostic ignored "-Wnoexcept-type" #endif +#elif defined __clang__ +// we'll just let this alone for now #elif defined _MSC_VER #pragma warning( push ) #pragma warning( disable : 4324 ) // structure was padded due to alignment specifier #pragma warning( disable : 4503 ) // decorated name horse shit #pragma warning( disable : 4702 ) // unreachable code -#endif // g++ +#pragma warning( disable: 4127 ) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk +#pragma warning( disable: 4505 ) // some other nonsense warning +#endif // clang++ vs. g++ vs. VC++ #include "sol/forward.hpp" #include "sol/state.hpp" diff --git a/sol/compatibility/compat-5.3.c b/sol/compatibility/compat-5.3.c index e87808c6..e61f37d1 100644 --- a/sol/compatibility/compat-5.3.c +++ b/sol/compatibility/compat-5.3.c @@ -534,7 +534,7 @@ static int compat53_skipBOM (compat53_LoadF *lf) { do { c = getc(lf->f); if (c == EOF || c != *(const unsigned char *)p++) return c; - lf->buff[lf->n++] = c; /* to be read by the parser */ + lf->buff[lf->n++] = (char)c; /* to be read by the parser */ } while (*p != '\0'); lf->n = 0; /* prefix matched; discard it */ return getc(lf->f); /* return next character */ @@ -611,7 +611,7 @@ COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char compat53_skipcomment(&lf, &c); /* re-read initial portion */ } if (c != EOF) - lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ + lf.buff[lf.n++] = (char)(c); /* 'c' is the first character of the stream */ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode); readstatus = ferror(lf.f); if (filename) fclose(lf.f); /* close file (even in case of errors) */ diff --git a/sol/container_traits.hpp b/sol/container_traits.hpp index 398f046b..ff0dd70b 100644 --- a/sol/container_traits.hpp +++ b/sol/container_traits.hpp @@ -1067,7 +1067,7 @@ namespace sol { static int set(lua_State* L) { stack_object value = stack_object(L, raw_index(3)); - if (type_of(L, 3) == type::nil) { + if (type_of(L, 3) == type::lua_nil) { return erase(L); } auto& self = get_src(L); diff --git a/sol/reference.hpp b/sol/reference.hpp index 092c8f5a..4d099f1b 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -300,7 +300,7 @@ namespace sol { ref = LUA_NOREF; return; } - if (r.get_type() == type::nil) { + if (r.get_type() == type::lua_nil) { ref = LUA_REFNIL; return; } diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index 261ef979..3e138a99 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -349,7 +349,7 @@ namespace stack { return true; } type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { + if (t == type::table || t == type::none || t == type::lua_nil) { lua_pop(L, 1); return true; } @@ -368,7 +368,7 @@ namespace stack { static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { tracking.use(1); type t = type_of(L, index); - if (t == type::table || t == type::none || t == type::nil || t == type::userdata) { + if (t == type::table || t == type::none || t == type::lua_nil || t == type::userdata) { return true; } handler(L, index, type::table, t, "value cannot not have a valid environment"); @@ -385,7 +385,7 @@ namespace stack { return true; } type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { + if (t == type::table || t == type::none || t == type::lua_nil) { lua_pop(L, 1); return true; } diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index fbed1cc7..79f6b9bb 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -119,7 +119,7 @@ namespace stack { tracking.use(1); int index = lua_absindex(L, relindex); - T arr; + T arr{}; std::size_t idx = 0; #if SOL_LUA_VERSION >= 503 // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3 @@ -151,8 +151,8 @@ namespace stack { for (int vi = 0; vi < lua_size::value; ++vi) { lua_pushinteger(L, i); lua_gettable(L, index); - type t = type_of(L, -1); - isnil = t == type::lua_nil; + type vt = type_of(L, -1); + isnil = vt == type::lua_nil; if (isnil) { if (i == 0) { break; @@ -749,7 +749,7 @@ namespace stack { typedef std::variant_size V_size; typedef std::integral_constant V_is_empty; - static V get_empty(std::true_type, lua_State* L, int index, record& tracking) { + static V get_empty(std::true_type, lua_State*, int, record&) { return V(); } @@ -758,7 +758,7 @@ namespace stack { // This should never be reached... // please check your code and understand what you did to bring yourself here std::abort(); - return V(std::in_place_index<0>, stack::get(L, index)); + return V(std::in_place_index<0>, stack::get(L, index, tracking)); } static V get_one(std::integral_constant, lua_State* L, int index, record& tracking) { diff --git a/tests/test_container_semantics.cpp b/tests/test_container_semantics.cpp index 7a956a2f..8ded28f6 100644 --- a/tests/test_container_semantics.cpp +++ b/tests/test_container_semantics.cpp @@ -403,13 +403,10 @@ void unordered_container_check(sol::state& lua, T& items) { 12, 13, 15, 16, 17, 18, 20 }; { - std::size_t idx = 0; - for (const auto& i : items) { - const auto& v = values[idx]; + for (const auto& v : values) { auto it = items.find(v); REQUIRE((it != items.cend())); REQUIRE((*it == v)); - ++idx; } } REQUIRE((s1 == 7)); @@ -512,13 +509,13 @@ end int v2 = lua["v2"]; int v3 = lua["v3"]; std::pair values[] = { - { 12, 31 }, - { 13, 23 }, - { 15, 25 }, - { 16, 26 }, - { 17, 27 }, - { 18, 28 }, - { 20, 30 } + { (short)12, 31 }, + { (short)13, 23 }, + { (short)15, 25 }, + { (short)16, 26 }, + { (short)17, 27 }, + { (short)18, 28 }, + { (short)20, 30 } }; { std::size_t idx = 0; @@ -608,23 +605,19 @@ void associative_unordered_container_check(sol::state& lua, T& items) { int v2 = lua["v2"]; int v3 = lua["v3"]; std::pair values[] = { - { 12, 31 }, - { 13, 23 }, - { 15, 25 }, - { 16, 26 }, - { 17, 27 }, - { 18, 28 }, - { 20, 30 } + { (short)12, 31 }, + { (short)13, 23 }, + { (short)15, 25 }, + { (short)16, 26 }, + { (short)17, 27 }, + { (short)18, 28 }, + { (short)20, 30 } }; - std::pair item_values[7]; { - std::size_t idx = 0; - for (const auto& i : items) { - const auto& v = values[idx]; + for (const auto& v : values) { auto it = items.find(v.first); REQUIRE((it != items.cend())); REQUIRE((it->second == v.second)); - ++idx; } } REQUIRE((s1 == 7)); @@ -862,11 +855,11 @@ TEST_CASE("containers/associative ordered containers", "check associative (map) lua.open_libraries(sol::lib::base); std::map items{ - { 11, 21 }, - { 12, 22 }, - { 13, 23 }, - { 14, 24 }, - { 15, 25 } + { (short)11, 21 }, + { (short)12, 22 }, + { (short)13, 23 }, + { (short)14, 24 }, + { (short)15, 25 } }; lua["c"] = &items; associative_ordered_container_check(lua, items); @@ -876,11 +869,11 @@ TEST_CASE("containers/associative ordered containers", "check associative (map) lua.open_libraries(sol::lib::base); std::multimap items{ - { 11, 21 }, - { 12, 22 }, - { 13, 23 }, - { 14, 24 }, - { 15, 25 } + { (short)11, 21 }, + { (short)12, 22 }, + { (short)13, 23 }, + { (short)14, 24 }, + { (short)15, 25 } }; lua["c"] = &items; associative_ordered_container_check(lua, items); @@ -893,11 +886,11 @@ TEST_CASE("containers/associative unordered containers", "check associative (map lua.open_libraries(sol::lib::base); std::unordered_map items{ - { 11, 21 }, - { 12, 22 }, - { 13, 23 }, - { 14, 24 }, - { 15, 25 } + { (short)11, 21 }, + { (short)12, 22 }, + { (short)13, 23 }, + { (short)14, 24 }, + { (short)15, 25 } }; lua["c"] = &items; associative_unordered_container_check(lua, items); @@ -907,11 +900,11 @@ TEST_CASE("containers/associative unordered containers", "check associative (map lua.open_libraries(sol::lib::base); std::unordered_multimap items{ - { 11, 21 }, - { 12, 22 }, - { 13, 23 }, - { 14, 24 }, - { 15, 25 } + { (short)11, 21 }, + { (short)12, 22 }, + { (short)13, 23 }, + { (short)14, 24 }, + { (short)15, 25 } }; lua["c"] = &items; associative_unordered_container_check(lua, items); diff --git a/tests/test_functions.cpp b/tests/test_functions.cpp index 21897274..1bb42abd 100644 --- a/tests/test_functions.cpp +++ b/tests/test_functions.cpp @@ -158,7 +158,6 @@ TEST_CASE("functions/return order and multi get", "Check if return order is in t lua.set_function("f", [] { return std::make_tuple(10, 11, 12); }); - int a = 0; lua.set_function("h", []() { return std::make_tuple(10, 10.0f); }); diff --git a/tests/test_inheritance.cpp b/tests/test_inheritance.cpp index 2d592ba8..0de061f9 100644 --- a/tests/test_inheritance.cpp +++ b/tests/test_inheritance.cpp @@ -267,6 +267,7 @@ tc3 = TestClass03(tc1) TestClass01& tc1 = lua["tc1"]; TestClass02& tc2 = lua["tc2"]; TestClass03& tc3 = lua["tc3"]; + REQUIRE(tc0.Thing() == 123); REQUIRE(tc1.a == 1); REQUIRE(tc2.a == 1); REQUIRE(tc2.b == 123); diff --git a/tests/test_storage.cpp b/tests/test_storage.cpp index f03e6c78..52f7cd23 100644 --- a/tests/test_storage.cpp +++ b/tests/test_storage.cpp @@ -4,12 +4,27 @@ #include TEST_CASE("storage/registry construction", "ensure entries from the registry can be retrieved") { - const auto& script = R"( + const auto& code = R"( function f() return 2 end )"; + sol::state lua; + lua.script(code); + sol::function f = lua["f"]; + sol::reference r = lua["f"]; + sol::function regf(lua, f); + sol::reference regr(lua, sol::ref_index(f.registry_index())); + bool isequal = f == r; + REQUIRE(isequal); + isequal = f == regf; + REQUIRE(isequal); + isequal = f == regr; + REQUIRE(isequal); +} + +TEST_CASE("storage/registry construction empty", "ensure entries from the registry can be retrieved") { sol::state lua; sol::function f = lua["f"]; sol::reference r = lua["f"]; diff --git a/tests/test_tables.cpp b/tests/test_tables.cpp index a2b92732..5c8445f8 100644 --- a/tests/test_tables.cpp +++ b/tests/test_tables.cpp @@ -193,7 +193,7 @@ TEST_CASE("tables/for_each", "Testing the use of for_each to get values from a l REQUIRE((value.as() == 123)); } break; - case sol::type::nil: + case sol::type::lua_nil: REQUIRE((value.as() == 3)); break; default: @@ -243,7 +243,7 @@ TEST_CASE("tables/for_each empty", "empty tables should not crash") { REQUIRE((value.as() == 123)); } break; - case sol::type::nil: + case sol::type::lua_nil: REQUIRE((value.as() == 3)); break; default: @@ -314,7 +314,7 @@ TEST_CASE("tables/iterators", "Testing the use of iteratrs to get values from a REQUIRE((value.as() == 123)); } break; - case sol::type::nil: + case sol::type::lua_nil: REQUIRE((value.as() == 3)); break; default: diff --git a/tests/tests.cpp b/tests/tests.cpp index 3ad515d8..d50b206d 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -289,7 +289,7 @@ TEST_CASE("object/conversions", "make sure all basic reference types can be made REQUIRE(ond.get_type() == sol::type::number); REQUIRE(osl.get_type() == sol::type::string); REQUIRE(os.get_type() == sol::type::string); - REQUIRE(omn.get_type() == sol::type::nil); + REQUIRE(omn.get_type() == sol::type::lua_nil); REQUIRE(oenv.get_type() == sol::type::table); } @@ -343,7 +343,7 @@ TEST_CASE("object/main_* conversions", "make sure all basic reference types can REQUIRE(ond.get_type() == sol::type::number); REQUIRE(osl.get_type() == sol::type::string); REQUIRE(os.get_type() == sol::type::string); - REQUIRE(omn.get_type() == sol::type::nil); + REQUIRE(omn.get_type() == sol::type::lua_nil); REQUIRE(oenv.get_type() == sol::type::table); }