From 9524ac428ae34aa188dd506454d332c6fb41a50b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 15 Feb 2019 19:42:03 +0100 Subject: [PATCH] src: remove invalid casts in options parser Fixes: https://github.com/nodejs/node/issues/26131 PR-URL: https://github.com/nodejs/node/pull/26139 Reviewed-By: Yang Guo Reviewed-By: Minwoo Jung Reviewed-By: Joyee Cheung --- src/node_options-inl.h | 13 +++++++------ src/node_options.h | 18 ++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index f482bcd36660ed..052c847f7ebdc4 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -148,7 +148,7 @@ void OptionsParser::Implies(const std::string& from, CHECK_NE(it, options_.end()); CHECK_EQ(it->second.type, kBoolean); implications_.emplace(from, Implication { - std::static_pointer_cast>(it->second.field), true + it->second.field, true }); } @@ -159,7 +159,7 @@ void OptionsParser::ImpliesNot(const std::string& from, CHECK_NE(it, options_.end()); CHECK_EQ(it->second.type, kBoolean); implications_.emplace(from, Implication { - std::static_pointer_cast>(it->second.field), false + it->second.field, false }); } @@ -205,8 +205,7 @@ auto OptionsParser::Convert( typename OptionsParser::Implication original, ChildOptions* (Options::* get_child)()) { return Implication { - std::static_pointer_cast>( - Convert(original.target_field, get_child)), + Convert(original.target_field, get_child), original.target_value }; } @@ -378,8 +377,10 @@ void OptionsParser::Parse( { auto implications = implications_.equal_range(name); - for (auto it = implications.first; it != implications.second; ++it) - *it->second.target_field->Lookup(options) = it->second.target_value; + for (auto it = implications.first; it != implications.second; ++it) { + *it->second.target_field->template Lookup(options) = + it->second.target_value; + } } const OptionInfo& info = it->second; diff --git a/src/node_options.h b/src/node_options.h index 4831bde121febc..b988c53b937fca 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -336,23 +336,17 @@ class OptionsParser { public: virtual ~BaseOptionField() {} virtual void* LookupImpl(Options* options) const = 0; - }; - - // Represents a field of type T within `Options`. - template - class OptionField : public BaseOptionField { - public: - typedef T Type; - T* Lookup(Options* options) const { - return static_cast(this->LookupImpl(options)); + template + inline T* Lookup(Options* options) const { + return static_cast(LookupImpl(options)); } }; // Represents a field of type T within `Options` that can be looked up // as a C++ member field. template - class SimpleOptionField : public OptionField { + class SimpleOptionField : public BaseOptionField { public: explicit SimpleOptionField(T Options::* field) : field_(field) {} void* LookupImpl(Options* options) const override { @@ -366,7 +360,7 @@ class OptionsParser { template inline T* Lookup(std::shared_ptr field, Options* options) const { - return std::static_pointer_cast>(field)->Lookup(options); + return field->template Lookup(options); } // An option consists of: @@ -383,7 +377,7 @@ class OptionsParser { // An implied option is composed of the information on where to store a // specific boolean value (if another specific option is encountered). struct Implication { - std::shared_ptr> target_field; + std::shared_ptr target_field; bool target_value; };