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] Build failure with Clang 5 -Wpedantic -Werror and #warning #1213

Closed
gracicot opened this issue Aug 18, 2021 · 6 comments · Fixed by #1216
Closed

[BUG] Build failure with Clang 5 -Wpedantic -Werror and #warning #1213

gracicot opened this issue Aug 18, 2021 · 6 comments · Fixed by #1216

Comments

@gracicot
Copy link

Describe the bug
This library won't compile with Clang 5, but do with all other version of clang.

Here's the error the compiler gives:

/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/include -I/home/runner/work/kangaru/kangaru/vcpkg/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/src -I/home/runner/work/kangaru/kangaru/vcpkg/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/src/../include -fPIC  -std=c++11  -Wall  -Wextra  -Wshadow  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety -g -MD -MT src/CMakeFiles/benchmark.dir/sysinfo.cc.o -MF src/CMakeFiles/benchmark.dir/sysinfo.cc.o.d -o src/CMakeFiles/benchmark.dir/sysinfo.cc.o -c /home/runner/work/kangaru/kangaru/vcpkg/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/src/sysinfo.cc
  /home/runner/work/kangaru/kangaru/vcpkg/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/src/sysinfo.cc:447:2: error: #warning is a language extension [-Werror,-Wpedantic]
  #warning "HOST_NAME_MAX not defined. using 64"
   ^
  /home/runner/work/kangaru/kangaru/vcpkg/buildtrees/benchmark/src/278e00fdbd-51ea7c4262.clean/src/sysinfo.cc:447:2: warning: "HOST_NAME_MAX not defined. using 64" [-W#warnings]
  1 warning and 1 error generated.

It seems benchmark uses a preprocessor extension to give a warning, but having -Wpedantic -Werror makes the warning of using the extension an error.

This doesn't happen with all other version of clang.

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

  • OS: Linux
  • Compiler and version: Clang 5

To reproduce
Steps to reproduce the behavior:

  1. checkout v1.5.5
  2. Run cmake .. -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_CXX_COMPILER=clang++-5
  3. Run ninja or make

Expected behavior
The library should build correctly

Additional context
It was found on github actions to test one of my libraries using Clang 5. Here's the full log.

It was installed using vcpkg. The original bug report is here: microsoft/vcpkg#19588

@dmah42
Copy link
Member

dmah42 commented Aug 19, 2021

is the issue the warning being escalated to an error, or is it that under clang 5 HOST_NAME_MAX isn't defined?

@gracicot
Copy link
Author

@dominichamon The fact that #warning is used even though -Wpendantic is definitely a bug. Couple it with -Werror and it's even worse, since it will cause build failures.

The fact that HOST_NAME_MAX is not defined might be a bug as well, but I don't know this library enough to assert this.

@dmah42
Copy link
Member

dmah42 commented Aug 23, 2021

oh i see, it's the use of #warning itself that's the problem now. i suppose it could be changed to a runtime log, but that's a semantic change.

would #prama message ("warning text") work better?

@LebedevRI
Copy link
Collaborator

I think this is working as intended.
We issue a warning that we will likely have issues due to that macro not being defined,
and you explicitly opted into promoting all warnings into errors.

@dmah42
Copy link
Member

dmah42 commented Aug 23, 2021

that's what i thought but the error message says "error: #warning is a language extension [-Werror,-Wpedantic]" which suggests the issue is with the use of #warning, not the warning itself.

@LebedevRI LebedevRI changed the title [BUG] Build failure with Clang 5 -Wpendantic -Werror and #warning [BUG] Build failure with Clang 5 -Wpedantic -Werror and #warning Aug 23, 2021
@gracicot
Copy link
Author

gracicot commented Aug 23, 2021

@LebedevRI There is two warning being issued:

  1. The compiler emits a warning because it's a non-standard extension. The buildsystem of this project adds -Wpedantic. Using #warning is nonstandard and Wpedantic is triggered. -Werror transforms this into an error.
  2. Then the compiler emits the warning for the message. It's correctly not treated as an error, but will nonetheless halt the compilation due to the previous error.

It seem #pragma message is much more portable, and also work with MSVC.

I'm curious though, is there a way to opt out of warning as error? Or even better, is there a way to fix this Line to be triggered under Clang 5?

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.

3 participants