Benjamin Bannier created MESOS-5772:
---------------------------------------
Summary: Implement clang-tidy check catching implicit narrowing in
use of Option
Key: MESOS-5772
URL: https://issues.apache.org/jira/browse/MESOS-5772
Project: Mesos
Issue Type: Bug
Reporter: Benjamin Bannier
{{Option<T>}} wraps the contained value by value, not by reference. This means
that the wrapped value cannot behave polymorphically. This is different from
{{Option}}'s previous behavior, so there might be existing code relying on
polymorphic behavior of values wrapped in {{Option}}. It is also easy to
inadvertently introduce wrong behavior when changing code from use of {{T}} to
use of {{Option<T>}}.
{code:title=Example}
struct Base {
virtual void f() { /* dummy impl, does nothing */ }
};
struct Derived : Base {
void f() override { perform_critical_task(); }
};
Option<Base> b = Dervided{}; // Implicit conversion from `Derived` to `Base`.
ASSERT_SOME(b);
b->f(); // Does nothing.
{code}
We should implement a check to catch implicit conversion like in above example.
Such a check would likely let explicit conversions pass.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)