Open
Description
Originally reported in https://users.rust-lang.org/t/broken-atomics-puzzle/9533
Consider this code
use std::sync::atomic::{AtomicBool, Ordering};
pub const A: AtomicBool = AtomicBool::new(false);
fn main() {
A.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst);
println!("A = {}", A.load(Ordering::SeqCst));
}
It compiles and runs cleanly, but produces unexpected results because const
is used instead of static
.
It would be nice to somehow give a warning for .compare_and_swap
call, but I am not sure it is possible.