Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 778db67

Browse filesBrowse files
addaleaxrvagg
authored andcommitted
src: remove invalid casts in options parser
Fixes: #26131 PR-URL: #26139 Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 4ca0789 commit 778db67
Copy full SHA for 778db67

File tree

Expand file treeCollapse file tree

2 files changed

+13
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-18
lines changed
Open diff view settings
Collapse file

‎src/node_options-inl.h‎

Copy file name to clipboardExpand all lines: src/node_options-inl.h
+7-6Lines 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;
Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,17 @@ class OptionsParser {
336336
public:
337337
virtual ~BaseOptionField() {}
338338
virtual void* LookupImpl(Options* options) const = 0;
339-
};
340-
341-
// Represents a field of type T within `Options`.
342-
template <typename T>
343-
class OptionField : public BaseOptionField {
344-
public:
345-
typedef T Type;
346339

347-
T* Lookup(Options* options) const {
348-
return static_cast<T*>(this->LookupImpl(options));
340+
template <typename T>
341+
inline T* Lookup(Options* options) const {
342+
return static_cast<T*>(LookupImpl(options));
349343
}
350344
};
351345

352346
// Represents a field of type T within `Options` that can be looked up
353347
// as a C++ member field.
354348
template <typename T>
355-
class SimpleOptionField : public OptionField<T> {
349+
class SimpleOptionField : public BaseOptionField {
356350
public:
357351
explicit SimpleOptionField(T Options::* field) : field_(field) {}
358352
void* LookupImpl(Options* options) const override {
@@ -366,7 +360,7 @@ class OptionsParser {
366360
template <typename T>
367361
inline T* Lookup(std::shared_ptr<BaseOptionField> field,
368362
Options* options) const {
369-
return std::static_pointer_cast<OptionField<T>>(field)->Lookup(options);
363+
return field->template Lookup<T>(options);
370364
}
371365

372366
// An option consists of:
@@ -383,7 +377,7 @@ class OptionsParser {
383377
// An implied option is composed of the information on where to store a
384378
// specific boolean value (if another specific option is encountered).
385379
struct Implication {
386-
std::shared_ptr<OptionField<bool>> target_field;
380+
std::shared_ptr<BaseOptionField> target_field;
387381
bool target_value;
388382
};
389383

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.