Warnings with gcc's -Weffc++
Closed this issue · 9 comments
If I compile my sources with gcc and with -Weffc++
I get the following warnings:
[1/3] Building CXX object CMakeFiles/trompeloeil-effcpp-test.dir/test.cpp.o
In file included from /home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil.hpp:29,
from /home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/trompeloeil.hpp:22,
from /home/sven/projects/trompeloeil-effcpp/test.cpp:2:
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/mock.hpp: In constructor 'trompeloeil::trace_agent::trace_agent(trompeloeil::location, const char*, trompeloeil::tracer*)':
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/mock.hpp:2129:5: warning: 'trompeloeil::trace_agent::os' should be initialized in the member initialization list [-Weffc++]
2129 | trace_agent(
| ^~~~~~~~~~~
In file included from /home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil.hpp:30:
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/lifetime.hpp: At global scope:
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/lifetime.hpp:62:8: warning: 'struct trompeloeil::lifetime_monitor' has pointer data members [-Weffc++]
62 | struct lifetime_monitor : public expectation
| ^~~~~~~~~~~~~~~~
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/lifetime.hpp:62:8: warning: but does not declare 'operator=(const trompeloeil::lifetime_monitor&)' [-Weffc++]
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/lifetime.hpp:136:22: note: pointer member 'trompeloeil::lifetime_monitor::call_name' declared here
136 | char const *call_name;
| ^~~~~~~~~
In file included from /home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil.hpp:37:
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:83:9: warning: 'class trompeloeil::sequence_matcher' has pointer data members [-Weffc++]
83 | class sequence_matcher : public list_elem<sequence_matcher>
| ^~~~~~~~~~~~~~~~
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:83:9: warning: but does not declare 'trompeloeil::sequence_matcher(const trompeloeil::sequence_matcher&)' [-Weffc++]
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:83:9: warning: or 'operator=(const trompeloeil::sequence_matcher&)' [-Weffc++]
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:162:17: note: pointer member 'trompeloeil::sequence_matcher::exp_name' declared here
162 | char const *exp_name;
| ^~~~~~~~
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp: In instantiation of 'std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = trompeloeil::sequence_type; _Args = {}; __detail::__unique_ptr_t<_Tp> = __detail::__unique_ptr_t<trompeloeil::sequence_type>]':
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:80:74: required from here
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/sequence.hpp:27:5: warning: 'trompeloeil::sequence_type::matchers' should be initialized in the member initialization list [-Weffc++]
27 | sequence_type() noexcept = default;
| ^~~~~~~~~~~~~
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/mock.hpp: In instantiation of 'trompeloeil::sequence_handler<N>::sequence_handler() [with long unsigned int M = 0; std::enable_if_t<(M == 0)>* <anonymous> = 0; long unsigned int N = 0]':
/nix/store/9hgsinpfgyvsd92v0wlvmxv9wnaal68r-gcc-13.2.0/include/c++/13.2.0/bits/unique_ptr.h:1070:30: required from 'std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = trompeloeil::sequence_handler<0>; _Args = {}; __detail::__unique_ptr_t<_Tp> = __detail::__unique_ptr_t<trompeloeil::sequence_handler<0> >]'
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/lifetime.hpp:137:95: required from here
/home/sven/projects/trompeloeil-effcpp/build/_deps/trompeloeil-src/include/doctest/../trompeloeil/mock.hpp:1750:5: warning: 'trompeloeil::sequence_handler<0>::matchers' should be initialized in the member initialization list [-Weffc++]
1750 | sequence_handler()
| ^~~~~~~~~~~~~~~~
[3/3] Linking CXX executable trompeloeil-effcpp-test
The code compiles, but with -Werror
the compiler bails out with an error.
See https://github.com/svenihoney/trompeloeil-effcpp for a minimal example project.
Hmm. I am unable to reproduce this. Where's the difference between your code and my attempt?
Hm. Can't reproduce it on godbolt as well, did you try my CMake project?
Perhaps try the following:
docker run --rm -it dockcross/linux-x64 bash
git clone https://github.com/svenihoney/trompeloeil-effcpp.git
cmake -B build -S trompeloeil-effcpp/
cmake --build build
and you will get the error.
I understand where the problem comes from, I was just baffled that my "obvious" reproduction didn't reproduce it and wondered if you could see a mistake.
Can you try branch Weffc
and see if it has resolved your issues?
The warnings about uninitialized member variables are, IMO, incorrect. They are non-trivial types with default constructors that are run at object creation time. Maybe something worth reporting to gcc?
The warnings about default generated operator=
were potential bugs, had any future change happened to accidentally call them, so thanks for those.
No, wait, I spoke too soon. The fix doesn't work with older C++ standards... 😞
Now the CI pipeline went green for all compilers and standards. Phiew.
Perfect, errors are gone!
Just tagged release v48 which includes this.