From b4516e4754feeb374a85502ba469606266fb35d6 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Wed, 14 Jan 2015 00:20:55 +0100 Subject: [PATCH] Fix #1844, eliminate pointers so typeid behaves Only the bare type is considered polymorphic/habving a vtable so therefore applying typeid to a pointer type doesn't behave as intended. --- src/auto4_lua_assfile.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 9d5bb25ab..b908ecf35 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -125,8 +125,8 @@ namespace { } template - T check_cast(U value) { - return typeid(T) == typeid(value) ? static_cast(value) : nullptr; + const T *check_cast_constptr(const U *value) { + return typeid(const T) == typeid(*value) ? static_cast(value) : nullptr; } } @@ -155,13 +155,13 @@ namespace Automation4 { set_field(L, "section", e->GroupHeader()); - if (auto info = check_cast(e)) { + if (auto info = check_cast_constptr(e)) { set_field(L, "raw", info->GetEntryData()); set_field(L, "key", info->Key()); set_field(L, "value", info->Value()); set_field(L, "class", "info"); } - else if (auto dia = check_cast(e)) { + else if (auto dia = check_cast_constptr(e)) { set_field(L, "raw", dia->GetEntryData()); set_field(L, "comment", dia->Comment); @@ -192,7 +192,7 @@ namespace Automation4 { set_field(L, "class", "dialogue"); } - else if (auto sty = check_cast(e)) { + else if (auto sty = check_cast_constptr(e)) { set_field(L, "raw", sty->GetEntryData()); set_field(L, "name", sty->name); @@ -623,7 +623,7 @@ namespace Automation4 { int LuaAssFile::LuaParseKaraokeData(lua_State *L) { auto e = LuaToAssEntry(L, ass); - auto dia = check_cast(e.get()); + auto dia = check_cast_constptr(e.get()); argcheck(L, !!dia, 1, "Subtitle line must be a dialogue line"); int idx = 0;