From c8279a1d897e7fb801676c266f0dd7a473159194 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 24 Nov 2016 17:03:53 +0100 Subject: [PATCH] Fix a dangerous c-cast in the cpp codegen --- contributors.txt | 1 + .../resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/contributors.txt b/contributors.txt index c3b6eebe4..70ea141df 100644 --- a/contributors.txt +++ b/contributors.txt @@ -123,3 +123,4 @@ YYYY/MM/DD, github id, Full name, email 2016/11/25, MrSampson, Oliver Sampson, olsam@quickaudio.com 2016/11/29, millergarym, Gary Miller, miller.garym@gmail.com 2016/11/29, wxio, Gary Miller, gm@wx.io +2016/11/29, Naios, Denis Blank, naios@users.noreply.github.com diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg index 07a90b91b..c5099c2fe 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg @@ -1048,8 +1048,8 @@ virtual antlrcpp::Any accept(tree::ParseTreeVisitor *visitor) override; VisitorDispatchMethod(method) ::= << antlrcpp::Any ::::accept(tree::ParseTreeVisitor *visitor) { - if (dynamic_cast\<Visitor*>(visitor) != nullptr) - return ((Visitor *)visitor)->visit(this); + if (auto parserVisitor = dynamic_cast\<Visitor*>(visitor)) + return parserVisitor->visit(this); else return visitor->visitChildren(this); }