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

Facing benchmark.h:1050:41: error: variable 'fn' has function type. Even with v1.3.1 #1062

Closed
digital10111 opened this issue Apr 16, 2019 · 14 comments · Fixed by #1846
Closed

Comments

@digital10111
Copy link

make
Scanning dependencies of target example
[  4%] Building CXX object example/CMakeFiles/example.dir/example.cpp.o
[  8%] Linking CXX executable example
[  8%] Built target example
Scanning dependencies of target multisink
[ 12%] Building CXX object example/CMakeFiles/multisink.dir/multisink.cpp.o
[ 16%] Linking CXX executable multisink
[ 16%] Built target multisink
Scanning dependencies of target spdlog-utests
[ 20%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_errors.cpp.o
[ 24%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_file_helper.cpp.o
[ 28%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_file_logging.cpp.o
[ 32%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_misc.cpp.o
[ 36%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_pattern_formatter.cpp.o
[ 40%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_async.cpp.o
[ 44%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_registry.cpp.o
[ 48%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_macros.cpp.o
[ 52%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/utils.cpp.o
[ 56%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/main.cpp.o
[ 60%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_mpmc_q.cpp.o
[ 64%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_fmt_helper.cpp.o
[ 68%] Linking CXX executable spdlog-utests
[ 68%] Built target spdlog-utests
Scanning dependencies of target formatter-bench
[ 72%] Building CXX object bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o
In file included from /tmp/tmp.CP8z4tf0ew/vendor/spdlog/bench/formatter-bench.cpp:6:0:
/usr/local/include/benchmark/benchmark.h: In instantiation of 'benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...)::<lambda(benchmark::State&)> [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]':
/usr/local/include/benchmark/benchmark.h:1050:48:   required from 'struct benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]::<lambda(class benchmark::State&)>'
/usr/local/include/benchmark/benchmark.h:1049:38:   required from 'benchmark::internal::Benchmark* benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]'
/tmp/tmp.CP8z4tf0ew/vendor/spdlog/bench/formatter-bench.cpp:49:79:   required from here
/usr/local/include/benchmark/benchmark.h:1050:41: error: variable 'fn' has function type
       name, [=](benchmark::State& st) { fn(st, args...); });
                                         ^
compilation terminated due to -Wfatal-errors.
bench/CMakeFiles/formatter-bench.dir/build.make:62: recipe for target 'bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o' failed
make[2]: *** [bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o] Error 1
CMakeFiles/Makefile2:1168: recipe for target 'bench/CMakeFiles/formatter-bench.dir/all' failed
make[1]: *** [bench/CMakeFiles/formatter-bench.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
@digital10111
Copy link
Author

cmake --build _builds --target install
Scanning dependencies of target example
[  4%] Building CXX object example/CMakeFiles/example.dir/example.cpp.o
[  8%] Linking CXX executable example
[  8%] Built target example
Scanning dependencies of target multisink
[ 12%] Building CXX object example/CMakeFiles/multisink.dir/multisink.cpp.o
[ 16%] Linking CXX executable multisink
[ 16%] Built target multisink
Scanning dependencies of target spdlog-utests
[ 20%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_errors.cpp.o
[ 24%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_file_helper.cpp.o
[ 28%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_file_logging.cpp.o
[ 32%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_misc.cpp.o
[ 36%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_pattern_formatter.cpp.o
[ 40%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_async.cpp.o
[ 44%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_registry.cpp.o
[ 48%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_macros.cpp.o
[ 52%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/utils.cpp.o
[ 56%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/main.cpp.o
[ 60%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_mpmc_q.cpp.o
[ 64%] Building CXX object tests/CMakeFiles/spdlog-utests.dir/test_fmt_helper.cpp.o
[ 68%] Linking CXX executable spdlog-utests
[ 68%] Built target spdlog-utests
Scanning dependencies of target formatter-bench
[ 72%] Building CXX object bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o
In file included from /tmp/tmp.CP8z4tf0ew/vendor/spdlog/bench/formatter-bench.cpp:6:0:
/usr/local/include/benchmark/benchmark.h: In instantiation of 'benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...)::<lambda(benchmark::State&)> [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]':
/usr/local/include/benchmark/benchmark.h:1050:48:   required from 'struct benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]::<lambda(class benchmark::State&)>'
/usr/local/include/benchmark/benchmark.h:1049:38:   required from 'benchmark::internal::Benchmark* benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]'
/tmp/tmp.CP8z4tf0ew/vendor/spdlog/bench/formatter-bench.cpp:49:79:   required from here
/usr/local/include/benchmark/benchmark.h:1050:41: error: variable 'fn' has function type
       name, [=](benchmark::State& st) { fn(st, args...); });
                                         ^
compilation terminated due to -Wfatal-errors.
bench/CMakeFiles/formatter-bench.dir/build.make:62: recipe for target 'bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o' failed
make[2]: *** [bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o] Error 1
CMakeFiles/Makefile2:1168: recipe for target 'bench/CMakeFiles/formatter-bench.dir/all' failed
make[1]: *** [bench/CMakeFiles/formatter-bench.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

Followed the documentation and got this.

@gabime
Copy link
Owner

gabime commented Apr 23, 2019

cant reproduce. probably wrong version of google benchmarks is used

@gabime gabime closed this as completed Apr 23, 2019
@emmenlau
Copy link
Contributor

emmenlau commented Feb 7, 2020

I'm facing this same issue with google benchmark v1.4.1. Also, this issue has been reported twice in the last year, see also #931 . I can find a reference of a similar error in https://stackoverflow.com/questions/34815698/c11-passing-function-as-lambda-parameter

I think it may be worthwhile to re-open this issue and check of wrapping in a function pointer helps?

@emmenlau
Copy link
Contributor

I also see this issue with google benchmark 1.5.0.

Could this be re-opened, or should I create a new issue?

@gabime gabime reopened this Feb 10, 2020
@gabime
Copy link
Owner

gabime commented Feb 10, 2020

Opened. @emmenlau If you have an idea how to fix, a PR would be much appreciated as I don't have time to get to it.

@emmenlau
Copy link
Contributor

Thanks @gabime . Currently I have no clue what may go wrong. The only related link is the stackoverflow discussion I linked above. It seems to say that the method should be encapsulated in a function pointer. However it partially contradicts itself later, so that I'm also at a loss here.
Any help would be appreciated!

@jafar75
Copy link

jafar75 commented May 24, 2020

@gabime I have the same problem. which version of google benchamrks have you tested with no errors?

@gabime
Copy link
Owner

gabime commented May 24, 2020

latest commit always worked for me

@xnervwang
Copy link

I have the same issue. I'm using the latest google benchmark at https://github.com/google/benchmark.

@MathiasMagnus
Copy link
Contributor

MathiasMagnus commented Feb 23, 2021

For those stumbling upon this error, it's a bug likely caused by compilers not properly decaying the supplied benchmarked function name into its pointer. Detailed answer here. Putting the address-of operator in front of the supplied function name (or in the context of GBench, the project could help by not simply capturing fn, but invoking std::decay on it as outlined in the linked answer) should solve the issue (at least it did for us, where it popped up while compiling the code using nvcc).

@MathiasMagnus
Copy link
Contributor

@gabime The solution is to provide benchmark cases not through a naked function name, but through their pointer. Put an ampersand in front if all supplied function names, for eg. here. (Function names aren't strictly speaking part of the language (they don't have a type). Language rules dictate in what contexts the names of functions (and other stuff) "decay" into things with types. I'm not a language lawyer, so I can't tell where some compiler is buggy or in which case it's actually correct not to decay, but the fix is simple nontheless: don't rely on decay mechanics.

@gabime
Copy link
Owner

gabime commented Feb 23, 2021

@MathiasMagnus Thanks. Can you confirm if this actually solves it for spdlog? I cant reproduce so I cant confirm myself.

@MathiasMagnus
Copy link
Contributor

@gabime Yes, I verified and it works. Built in WSL using Ubuntu 18.04, installed the oldest GCC in the repo (g++-5) and tried building, get the same error. Add 3 &s on lines 37,55,76 and it compiles.

@MathiasMagnus
Copy link
Contributor

cmake -D CMAKE_CXX_COMPILER=g++-5 -D SPDLOG_BUILD_BENCH=ON -D CMAKE_PREFIX_PATH=/home/mate/benchmark/install ..
-- The CXX compiler identification is GNU 5.5.0
-- Check for working CXX compiler: /usr/bin/g++-5
-- Check for working CXX compiler: /usr/bin/g++-5 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build spdlog: 1.8.2
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Build type: Release
-- Generating example(s)
-- Generating benchmarks
-- Generating install
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mate/spdlog/build
mate@MATTY-GL702ZC:~/spdlog/build$ grep RegisterBenchmark ../bench/formatter-bench.cpp
        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
        //        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
        //        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern)->Iterations(2500000);
        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
mate@MATTY-GL702ZC:~/spdlog/build$ cmake --build . --target formatter-bench | grep error
In file included from /home/mate/spdlog/bench/formatter-bench.cpp:6:0:
/home/mate/benchmark/install/include/benchmark/benchmark.h: In instantiation of ‘benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...)::<lambda(benchmark::State&)> [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’:
/home/mate/benchmark/install/include/benchmark/benchmark.h:1062:48:   required from ‘struct benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]::<lambda(class benchmark::State&)>’
/home/mate/benchmark/install/include/benchmark/benchmark.h:1061:38:   required from ‘benchmark::internal::Benchmark* benchmark::RegisterBenchmark(const char*, Lambda&&, Args&& ...) [with Lambda = void (&)(benchmark::State&, std::__cxx11::basic_string<char>); Args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’
/home/mate/spdlog/bench/formatter-bench.cpp:37:79:   required from here
/home/mate/benchmark/install/include/benchmark/benchmark.h:1062:41: error: variable ‘fn’ has function type
       name, [=](benchmark::State& st) { fn(st, args...); });
mate@MATTY-GL702ZC:~/spdlog/build$ grep RegisterBenchmark ../bench/formatter-bench.cpp
        benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
        //        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
        //        benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
        benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern)->Iterations(2500000);
        benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
mate@MATTY-GL702ZC:~/spdlog/build$ cmake --build . --target formatter-bench
[ 80%] Built target spdlog
Scanning dependencies of target formatter-bench
[ 90%] Building CXX object bench/CMakeFiles/formatter-bench.dir/formatter-bench.cpp.o
[100%] Linking CXX executable formatter-bench
[100%] Built target formatter-bench

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.

6 participants