You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing the reference through a T [const]& function parameter bypassed std::reference_wrapper's protection against being constructed from a temporary. Correct code would have Foo's ctor also taking a std::reference_wrapper<T> rather than a T&. This seems like the sort of thing clang-tidy ought to be able to spot and... discourage.
I propose that clang-tidy should flag construction of a std::reference_wrapper<T> from (at least) a T&, if the latter is a function parameter, and should recommend changing the parameter type from T& to std::reference_wrapper<T>. (Ideally this would cover convertible types, but that might be difficult for some potential conversions. Possibly it could at least cover U& where U is a subclass of T.)
The text was updated successfully, but these errors were encountered:
We (CMake) recently ran into a bug that can be summarized thusly:
Passing the reference through a
T [const]&
function parameter bypassedstd::reference_wrapper
's protection against being constructed from a temporary. Correct code would haveFoo
's ctor also taking astd::reference_wrapper<T>
rather than aT&
. This seems like the sort of thing clang-tidy ought to be able to spot and... discourage.I propose that clang-tidy should flag construction of a
std::reference_wrapper<T>
from (at least) aT&
, if the latter is a function parameter, and should recommend changing the parameter type fromT&
tostd::reference_wrapper<T>
. (Ideally this would cover convertible types, but that might be difficult for some potential conversions. Possibly it could at least coverU&
whereU
is a subclass ofT
.)The text was updated successfully, but these errors were encountered: