-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Comments
Followed the documentation and got this. |
cant reproduce. probably wrong version of google benchmarks is used |
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? |
I also see this issue with google benchmark 1.5.0. Could this be re-opened, or should I create a new issue? |
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. |
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. |
@gabime I have the same problem. which version of google benchamrks have you tested with no errors? |
latest commit always worked for me |
I have the same issue. I'm using the latest google benchmark at https://github.com/google/benchmark. |
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 |
@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. |
@MathiasMagnus Thanks. Can you confirm if this actually solves it for spdlog? I cant reproduce so I cant confirm myself. |
@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 |
|
The text was updated successfully, but these errors were encountered: