google / benchmark

A microbenchmark support library
Apache License 2.0
8.69k stars 1.59k forks source link

[BUG] `DoNotOptimize(T &&)` should not be deprecated #1584

Closed davidstone closed 1 year ago

davidstone commented 1 year ago

Describe the bug

In https://github.com/google/benchmark/pull/1493, the T const & overload of DoNotOptimize was deprecated because the compiler is still able to make assumptions about the value of the variable. However, it is unclear whether this concern would apply to an rvalue reference overload.

To reproduce

int f() {
    return 5;
}
void g() {
    benchmark::DoNotOptimize(f());
}

Expected behavior

No warning is emitted.

dmah42 commented 1 year ago

@ckennelly is the expert. i defer to them.

horenmar commented 1 year ago

Bumping this because I share @davidstone's opinion and also because I have to deal with about 50 warnings caused by this change.