Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] DoNotOptimize const & overload chosen for non-const lvalue references #1619

Closed
eseiler opened this issue Jul 3, 2023 · 4 comments · Fixed by #1622
Closed

[BUG] DoNotOptimize const & overload chosen for non-const lvalue references #1619

eseiler opened this issue Jul 3, 2023 · 4 comments · Fixed by #1622

Comments

@eseiler
Copy link
Contributor

eseiler commented Jul 3, 2023

Describe the bug
After df9a99d, const & overloads are chosen where previously the & overload was chosen. This leads to deprecation warnings where IMO there should be none. const & takes precedence over the new && overload.

Godbolt: https://godbolt.org/z/5s6sKT7dc

Click to show code from godbolt example
#include <benchmark/benchmark.h>

#include <algorithm>
#include <vector>

static void test(benchmark::State & state)
{
    std::vector<int> vec(100);

    for (auto _ : state)
    {
        std::fill(vec.begin(), vec.end(), 1);
        benchmark::DoNotOptimize(vec);
    }
}
BENCHMARK(test);

BENCHMARK_MAIN();
<source>: In function 'void test(benchmark::State&)':
<source>:13:33: error: 'typename std::enable_if<((! std::is_trivially_copyable<_Tp>::value) || (sizeof (Tp) > sizeof (Tp*)))>::type benchmark::DoNotOptimize(const Tp&) [with Tp = std::vector<int>; typename std::enable_if<((! std::is_trivially_copyable<_Tp>::value) || (sizeof (Tp) > sizeof (Tp*)))>::type = void]' is deprecated: The const-ref version of this method can permit undesired compiler optimizations in benchmarks [-Werror=deprecated-declarations]
   13 |         benchmark::DoNotOptimize(vec);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from <source>:1:
/opt/compiler-explorer/libs/google-benchmark/trunk/include/benchmark/benchmark.h:502:5: note: declared here
  502 |     DoNotOptimize(Tp const& value) {
      |     ^~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

System
Which OS, compiler, and compiler version are you using:

  • OS: Ubuntu 22.04.2 LTS
  • Compiler and version: gcc version 12.3.0 (locally), 13.1.0 (godbolt)

To reproduce
See bug description.

Expected behavior
IMO, it should still work. There probably needs to be both & and && overloads. It does work if I add additional & overloads.

@eseiler
Copy link
Contributor Author

eseiler commented Jul 4, 2023

If this is confirmed to be a bug, I could offer to provide a PR with the code changes and test cases.

@LebedevRI
Copy link
Collaborator

I'm pretty sure #1608 should have only affected rvalues, so this does seem like a bug.

@LebedevRI
Copy link
Collaborator

LebedevRI commented Jul 4, 2023

Hm, i'm confused. DoNotOptimize const & overload change happened much earlier than df9a99d,
it was already present in v1.8.0, yet i concur that i'm also only now started getting those warnings, in v1.8.1:
https://github.com/darktable-org/rawspeed/actions/runs/5454117056/jobs/9923812487?pr=494

@dmah42 so i guess that means the original #1493 didn't prohibit all the cases?

@LebedevRI
Copy link
Collaborator

Ok, no, let me backtrack, those are false-positives, this is a bug. @eseiler patches most welcomed!
Looks like we'll be getting .2 soon? (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants