Skip to content

New warnings with Clang10 #2225

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

Closed
apollo13 opened this issue May 22, 2020 · 7 comments
Closed

New warnings with Clang10 #2225

apollo13 opened this issue May 22, 2020 · 7 comments

Comments

@apollo13
Copy link
Contributor

apollo13 commented May 22, 2020

Issue description

After upgrading to Clang10 I see new warnings (which result in errors due to -Werror) on my builds with pybind11 2.5.0:

/home/florian/sources/bap_server/so/pybind11/include/pybind11/pybind11.h:1093:9: error: expression result unused [-Werror,-Wunused-value]
        PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/bap_server/so/pybind11/include/pybind11/detail/common.h:662:47: note: expanded from macro 'PYBIND11_EXPAND_SIDE_EFFECTS'
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
                                              ^                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/bap_server/so/gina/gina.cpp:176:4: note: in instantiation of function template specialization 'pybind11::class_<bap::GINACallbackWrapper>::class_<>' requested here
   py::class_<bap::GINACallbackWrapper>(m, "GINACallbackWrapper").def("callback", &bap::GINACallbackWrapper::callback);

Reproducible example code

As far as I can see this would happen for every usage of class_ and should immediately show up as soon as Clang10 is used and -Wunused-value is enabled. I was able to locally disable it via:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
        /* Register base classes specified via template arguments to class_, if any */
        PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
#pragma clang diagnostic pop
@philbucher
Copy link
Contributor

I can confirm that this problem happens and that the proposed solution silences the warning
I don't know what happens in the background and if the warning should rather be fixed than just silenced

Thanks

@bstaletic
Copy link
Collaborator

I can't reproduce this "just by using clang++ 10 and -Wunused-value". Can someone provide actual code that triggers this warning?

As far as I can see, the solution would be to just slap (void) or [[maybe_unused]], but it would be nice to confirm this is the actual problem.

@apollo13
Copy link
Contributor Author

@bstaletic Mhm, good question; I have uploaded https://github.com/apollo13/pybind11-example which triggers the issue for me. Ie just execute build.sh in the checkout (don't forget to initialize submodules):

-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python3.8 (found version "3.8.3") 
-- Found PythonLibs: /usr/lib64/libpython3.8.so
-- pybind11 v2.5.dev1
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- LTO enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/florian/sources/pybind11-example
/usr/bin/cmake -S/home/florian/sources/pybind11-example -B/home/florian/sources/pybind11-example --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/florian/sources/pybind11-example/CMakeFiles /home/florian/sources/pybind11-example/CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/florian/sources/pybind11-example'
make  -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/depend
make[2]: Entering directory '/home/florian/sources/pybind11-example'
cd /home/florian/sources/pybind11-example && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/florian/sources/pybind11-example /home/florian/sources/pybind11-example /home/florian/sources/pybind11-example /home/florian/sources/pybind11-example /home/florian/sources/pybind11-example/CMakeFiles/example.dir/DependInfo.cmake --color=
Dependee "/home/florian/sources/pybind11-example/CMakeFiles/example.dir/DependInfo.cmake" is newer than depender "/home/florian/sources/pybind11-example/CMakeFiles/example.dir/depend.internal".
Dependee "/home/florian/sources/pybind11-example/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/florian/sources/pybind11-example/CMakeFiles/example.dir/depend.internal".
Scanning dependencies of target example
make[2]: Leaving directory '/home/florian/sources/pybind11-example'
make  -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/build
make[2]: Entering directory '/home/florian/sources/pybind11-example'
[ 50%] Building CXX object CMakeFiles/example.dir/example.cpp.o
/usr/bin/clang++  -Dexample_EXPORTS -I/home/florian/sources/pybind11-example/pybind11/include -I/usr/include/python3.8  -fPIC -fvisibility=hidden   -flto -o CMakeFiles/example.dir/example.cpp.o -c /home/florian/sources/pybind11-example/example.cpp
In file included from /home/florian/sources/pybind11-example/example.cpp:1:
/home/florian/sources/pybind11-example/pybind11/include/pybind11/pybind11.h:1120:9: warning: expression result unused [-Wunused-value]
        PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/pybind11-example/pybind11/include/pybind11/detail/common.h:679:47: note: expanded from macro 'PYBIND11_EXPAND_SIDE_EFFECTS'
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
                                              ^                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/pybind11-example/example.cpp:19:3: note: in instantiation of function template specialization 'pybind11::class_<Example>::class_<>' requested here
  py::class_<Example>(m, "Example").def( "abc", &Example::abc );
  ^
1 warning generated.
[100%] Linking CXX shared module example.cpython-38-x86_64-linux-gnu.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/example.dir/link.txt --verbose=1
/usr/bin/clang++ -fPIC   -shared  -o example.cpython-38-x86_64-linux-gnu.so CMakeFiles/example.dir/example.cpp.o  -flto 
make[2]: Leaving directory '/home/florian/sources/pybind11-example'
[100%] Built target example
make[1]: Leaving directory '/home/florian/sources/pybind11-example'
/usr/bin/cmake -E cmake_progress_start /home/florian/sources/pybind11-example/CMakeFiles 0

@apollo13
Copy link
Contributor Author

Note that I am on Fedora 32, executing the clang++ invocation manually with -v yields:

clang version 10.0.0 (Fedora 10.0.0-2.fc32)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 (in-process)
 "/usr/bin/clang-10" -cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -flto -flto-unit -disable-free -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/10.0.0 -D example_EXPORTS -I /home/florian/sources/pybind11-example/pybind11/include -I /usr/include/python3.8 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/florian/sources/pybind11-example -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o CMakeFiles/example.dir/example.cpp.o -x c++ /home/florian/sources/pybind11-example/example.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/florian/sources/pybind11-example/pybind11/include
 /usr/include/python3.8
 /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10
 /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux
 /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward
 /usr/local/include
 /usr/lib64/clang/10.0.0/include
 /usr/include
End of search list.
In file included from /home/florian/sources/pybind11-example/example.cpp:1:
/home/florian/sources/pybind11-example/pybind11/include/pybind11/pybind11.h:1120:9: warning: expression result unused [-Wunused-value]
        PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/pybind11-example/pybind11/include/pybind11/detail/common.h:679:47: note: expanded from macro 'PYBIND11_EXPAND_SIDE_EFFECTS'
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
                                              ^                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/florian/sources/pybind11-example/example.cpp:19:3: note: in instantiation of function template specialization 'pybind11::class_<Example>::class_<>' requested here
  py::class_<Example>(m, "Example").def( "abc", &Example::abc );
  ^
1 warning generated.

If you have the same "default" flags the issue should be reproducible.

@apollo13
Copy link
Contributor Author

diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h
index 8b609e7..33805e0 100644
--- a/include/pybind11/detail/common.h
+++ b/include/pybind11/detail/common.h
@@ -676,7 +676,7 @@ inline void ignore_unused(const int *) { }
 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
 #else
 using expand_side_effects = bool[];
-#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
+#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (void)pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
 #endif
 
 PYBIND11_NAMESPACE_END(detail)

Adding (void) seems to fix it for me, cannot say if this causes other issues though (ie I just tried to ensure that the warnings are gone, the full testsuite might see issues with it).

@bstaletic
Copy link
Collaborator

I think that is fine. Mind submitting a pull request?

apollo13 added a commit to apollo13/pybind11 that referenced this issue Jul 12, 2020
@YannickJadoul
Copy link
Collaborator

Merged #2225. Thanks again! :-)

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

No branches or pull requests

4 participants