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
fix gcc7.5 compile error #1379
base: main
Are you sure you want to change the base?
fix gcc7.5 compile error #1379
Conversation
Can you point me at the test within this repo that fails when you build the benchmark itself with GCC7.5? |
+_+ |
Then please add a test that fails without this fix :) |
Thanks for your guidance, testcase added, It seems that lambda is not compatible with compiler, use According to |
I'm not sure why what is the problem with just defining the macro? |
Ah...which "macro" ? no macro now. I have added |
I believe the previous fix is much less controversial. |
Ah I got it ... I have tried to add #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
#define BENCHMARK_HAS_CXX14
#endif
...
#if BENCHMARCK_HAS_CXX14
...
#elif BENCHMARCK_HAS_CXX11
...
#endif But the default compile option is $ cd benchmark/build
$ make VERBOSE=1
.... -std=c++11 .... That means GCC7.5 -std=c++11 could not use lamda, use |
Err, i'm being stupid again.
|
for clang/gcc11, it's fine; for c++11, lamda not support capture initializer, for example this code not work: int value1=1;
auto x = [=, value2=value1](){...} |
That is why I use |
Err... is this PR acceptable ? @LebedevRI |
ping for @LebedevRI to comment :) |
I think there may be a translation issue here. This sounds like a GCC7 bug, so the fix should not affect anything else. template <class Lambda, class... Args>
internal::Benchmark* RegisterBenchmark(const char* name, Lambda&& fn,
Args&&... args) {
+#if !defined(__GNUC__) || (defined(BENCHMARK_GCC_VERSION) && BENCHMARK_GCC_VERSION >= 800) || __cplusplus >= 201402L
return benchmark::RegisterBenchmark(
name, [=](benchmark::State& st) { fn(st, args...); });
+#else
+ // Workaround GCC7.5 C++ bug, see https://github.com/google/benchmark/pull/1379.
+ auto func = std::bind(std::forward<Lambda>(fn), std::placeholders::_1,
+ std::forward<Args>(args)...);
+ return benchmark::RegisterBenchmark(name,
+ [=](benchmark::State& st) { func(st); });
+#endif
} |
Context
I tried to compile google/uVkCompute with GCC7.5, got some error:
The key problem is construct lambda in gcc7.5, please build this snippet and have a try:
auto fff = [=](){ fn(args...); };
is fine in clang/gcc11, but does not work in gcc7.5.please check