Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove invalid casts in options parser #26139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void OptionsParser<Options>::Implies(const std::string& from,
CHECK_NE(it, options_.end());
CHECK_EQ(it->second.type, kBoolean);
implications_.emplace(from, Implication {
std::static_pointer_cast<OptionField<bool>>(it->second.field), true
it->second.field, true
});
}

Expand All @@ -159,7 +159,7 @@ void OptionsParser<Options>::ImpliesNot(const std::string& from,
CHECK_NE(it, options_.end());
CHECK_EQ(it->second.type, kBoolean);
implications_.emplace(from, Implication {
std::static_pointer_cast<OptionField<bool>>(it->second.field), false
it->second.field, false
});
}

Expand Down Expand Up @@ -205,8 +205,7 @@ auto OptionsParser<Options>::Convert(
typename OptionsParser<ChildOptions>::Implication original,
ChildOptions* (Options::* get_child)()) {
return Implication {
std::static_pointer_cast<OptionField<bool>>(
Convert(original.target_field, get_child)),
Convert(original.target_field, get_child),
original.target_value
};
}
Expand Down Expand Up @@ -378,8 +377,10 @@ void OptionsParser<Options>::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<bool>(options) =
it->second.target_value;
}
}

const OptionInfo& info = it->second;
Expand Down
18 changes: 6 additions & 12 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,17 @@ class OptionsParser {
public:
virtual ~BaseOptionField() {}
virtual void* LookupImpl(Options* options) const = 0;
};

// Represents a field of type T within `Options`.
template <typename T>
class OptionField : public BaseOptionField {
public:
typedef T Type;

T* Lookup(Options* options) const {
return static_cast<T*>(this->LookupImpl(options));
template <typename T>
inline T* Lookup(Options* options) const {
return static_cast<T*>(LookupImpl(options));
}
};

// Represents a field of type T within `Options` that can be looked up
// as a C++ member field.
template <typename T>
class SimpleOptionField : public OptionField<T> {
class SimpleOptionField : public BaseOptionField {
public:
explicit SimpleOptionField(T Options::* field) : field_(field) {}
void* LookupImpl(Options* options) const override {
Expand All @@ -356,7 +350,7 @@ class OptionsParser {
template <typename T>
inline T* Lookup(std::shared_ptr<BaseOptionField> field,
Options* options) const {
return std::static_pointer_cast<OptionField<T>>(field)->Lookup(options);
return field->template Lookup<T>(options);
}

// An option consists of:
Expand All @@ -373,7 +367,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<OptionField<bool>> target_field;
std::shared_ptr<BaseOptionField> target_field;
bool target_value;
};

Expand Down