Skip to content

Commit

Permalink
[framework] Fix deprecated AddIfSupported scalar conversion helper (#…
Browse files Browse the repository at this point in the history
…15657)

* [framework] Fix deprecated AddIfSupported scalar conversion helper

The prior implementation of this template function contained broken code,
but was never compiled so we never noticed.
  • Loading branch information
jwnimmer-tri committed Aug 24, 2021
1 parent f71f1e0 commit 6ce4018
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion systems/framework/system_scalar_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SystemScalarConverter {
DRAKE_DEPRECATED("2021-10-01",
"User-defined scalar types cannot be added.")
void AddIfSupported() {
AddIfSupported<S, T, U>(GuaranteedSubtypePreservation::kEnabled);
MaybeAddConstructor<true, S, T, U>();
}

/// Removes from this converter all pairs where `other.IsConvertible<T, U>`
Expand Down
12 changes: 12 additions & 0 deletions systems/framework/test/system_scalar_converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ GTEST_TEST(SystemScalarConverterTest, Remove) {
dut.Convert<AutoDiffXd, double>(system)));
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
GTEST_TEST(SystemScalarConverterTest, DeprecatedAddIfSupported) {
// The deprecated function AddIfSupported no longer serves any useful purpose,
// because there are no public functions that allow us to observe its effects,
// but we should ensure that it at least _compiles_ if someone does try to use
// it.
SystemScalarConverter dut(SystemTypeTag<FromDoubleSystem>{});
dut.AddIfSupported<FromDoubleSystem, double, float>();
}
#pragma GCC diagnostic pop

} // namespace
} // namespace systems
} // namespace drake

0 comments on commit 6ce4018

Please sign in to comment.