od: warning: function pointer comparisons do not produce meaningful results · Issue #7187 · uutils/coreutils · GitHub
More Web Proxy on the site http://driver.im/
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
Compiling uu_sum v0.0.29(/home/drebbe/dev/coreutils/src/uu/sum)
warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
--> src/uu/od/src/formatteriteminfo.rs:29:45
|
29 | (IntWriter(a),IntWriter(b)) => a == b,
| ^^^^^^
|
= note: the address of the same function can vary between different codegen units
= note: furthermore, different functions could have the same address after being merged together
= note:for more information visit<https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>
= note: `#[warn(unpredictable_function_pointer_comparisons)]` on by default
help: refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint
|
29 | (IntWriter(a),IntWriter(b)) => std::ptr::fn_addr_eq(*a,*b),
| ++++++++++++++++++++++ ~~~ +
warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
--> src/uu/od/src/formatteriteminfo.rs:30:49
|
30 | (FloatWriter(a),FloatWriter(b)) => a == b,
| ^^^^^^
|
= note: the address of the same function can vary between different codegen units
= note: furthermore, different functions could have the same address after being merged together
= note:for more information visit<https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>help:refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint
|
30 | (FloatWriter(a),FloatWriter(b)) => std::ptr::fn_addr_eq(*a,*b),
| ++++++++++++++++++++++ ~~~ +
The text was updated successfully, but these errors were encountered:
It seems that this is not a sum issue but an od issue. It is possible to reproduce the issue by running cargo build from src/uu/od . The source of the issue (src/uu/od/src/formatteriteminfo.rs) also informs about od.
Using fn_addr_eq for comparison will lead to broken tests. For example:
Here is a commit & CI build. The test results look strange, but reading the docs for fn_addr_eq could shed light on that.
The first assumption here is that PartialEq and Eq for FormatterItemInfo should take into account byte_size, print_width fields, and the type of formatter, but not the addresses of formatting functions. In general, comparing addresses could be useless because equivalent (in terms of behavior) functions could have different addresses.
I'm not sure we really need manual PartialEq and Eq implementations here. As the simplest first step, I asked the compiler to generate the trait implementations and allowed it to decide how to compare. As a result, I see the issue is gone, and the tests pass (cargo test for the whole coreutils and the od module). Here is PR for reviewing & further discussion.
cakebaker
changed the title
sum: warning: function pointer comparisons do not produce meaningful results
od: warning: function pointer comparisons do not produce meaningful results
Jan 26, 2025
This might be a false positive, I had nightly defaulted by accident and ran across this warning. Stable 1.84 doesn't display this warning.
The text was updated successfully, but these errors were encountered: