Skip to content

Commit 35e6070

Browse files
committed
src: remove invalid casts in options parser
Fixes: #26131 PR-URL: #26139 Reviewed-By: Yang Guo <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 45b7c98 commit 35e6070

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/node_options-inl.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void OptionsParser<Options>::Implies(const std::string& from,
148148
CHECK_NE(it, options_.end());
149149
CHECK_EQ(it->second.type, kBoolean);
150150
implications_.emplace(from, Implication {
151-
std::static_pointer_cast<OptionField<bool>>(it->second.field), true
151+
it->second.field, true
152152
});
153153
}
154154

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

@@ -205,8 +205,7 @@ auto OptionsParser<Options>::Convert(
205205
typename OptionsParser<ChildOptions>::Implication original,
206206
ChildOptions* (Options::* get_child)()) {
207207
return Implication {
208-
std::static_pointer_cast<OptionField<bool>>(
209-
Convert(original.target_field, get_child)),
208+
Convert(original.target_field, get_child),
210209
original.target_value
211210
};
212211
}
@@ -378,8 +377,10 @@ void OptionsParser<Options>::Parse(
378377

379378
{
380379
auto implications = implications_.equal_range(name);
381-
for (auto it = implications.first; it != implications.second; ++it)
382-
*it->second.target_field->Lookup(options) = it->second.target_value;
380+
for (auto it = implications.first; it != implications.second; ++it) {
381+
*it->second.target_field->template Lookup<bool>(options) =
382+
it->second.target_value;
383+
}
383384
}
384385

385386
const OptionInfo& info = it->second;

src/node_options.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,17 @@ class OptionsParser {
326326
public:
327327
virtual ~BaseOptionField() {}
328328
virtual void* LookupImpl(Options* options) const = 0;
329-
};
330-
331-
// Represents a field of type T within `Options`.
332-
template <typename T>
333-
class OptionField : public BaseOptionField {
334-
public:
335-
typedef T Type;
336329

337-
T* Lookup(Options* options) const {
338-
return static_cast<T*>(this->LookupImpl(options));
330+
template <typename T>
331+
inline T* Lookup(Options* options) const {
332+
return static_cast<T*>(LookupImpl(options));
339333
}
340334
};
341335

342336
// Represents a field of type T within `Options` that can be looked up
343337
// as a C++ member field.
344338
template <typename T>
345-
class SimpleOptionField : public OptionField<T> {
339+
class SimpleOptionField : public BaseOptionField {
346340
public:
347341
explicit SimpleOptionField(T Options::* field) : field_(field) {}
348342
void* LookupImpl(Options* options) const override {
@@ -356,7 +350,7 @@ class OptionsParser {
356350
template <typename T>
357351
inline T* Lookup(std::shared_ptr<BaseOptionField> field,
358352
Options* options) const {
359-
return std::static_pointer_cast<OptionField<T>>(field)->Lookup(options);
353+
return field->template Lookup<T>(options);
360354
}
361355

362356
// An option consists of:
@@ -373,7 +367,7 @@ class OptionsParser {
373367
// An implied option is composed of the information on where to store a
374368
// specific boolean value (if another specific option is encountered).
375369
struct Implication {
376-
std::shared_ptr<OptionField<bool>> target_field;
370+
std::shared_ptr<BaseOptionField> target_field;
377371
bool target_value;
378372
};
379373

0 commit comments

Comments
 (0)