jetbrains-academy / CppBasics

Learn fundamentals of C/C++ while developing simple arcade game
MIT License
4 stars 1 forks source link

google-test subdirectory fails to build (-Werror) #10

Closed telans closed 1 year ago

telans commented 1 year ago

In attempting Task 2/14, compilation fails when checking the answer as google-test fails to build due to -Werror=maybe-uninitialized:

====================[ Build | WarmUp-MovingOn-MoveAnObject-test | Debug ]=======
/home/telans/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cmake --build /home/telans/CLionProjects/C++Basics/cmake-build-debug --target WarmUp-MovingOn-MoveAnObject-test -- -j 14
[ 16%] Built target WarmUp-MovingOn-MoveAnObject-test-src-part
[ 33%] Building CXX object /home/telans/CLionProjects/C++Basics/test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
In file included from /home/telans/CLionProjects/C++Basics/test-framework/googletest-src/googletest/src/gtest-all.cc:42:
/home/telans/CLionProjects/C++Basics/test-framework/googletest-src/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
/home/telans/CLionProjects/C++Basics/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1224:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
 1224 |   StackLowerThanAddress(&dummy, &result);
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/home/telans/CLionProjects/C++Basics/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1214:13: note: by argument 1 of type ‘const void*’ to ‘void testing::internal::StackLowerThanAddress(const void*, bool*)’ declared here
 1214 | static void StackLowerThanAddress(const void* ptr, bool* result) {
      |             ^~~~~~~~~~~~~~~~~~~~~
/home/telans/CLionProjects/C++Basics/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1222:7: note: ‘dummy’ declared here
 1222 |   int dummy;
      |       ^~~~~
cc1plus: all warnings being treated as errors
make[3]: *** [/home/telans/CLionProjects/C++Basics/test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/build.make:76: /home/telans/CLionProjects/C++Basics/test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:1045: /home/telans/CLionProjects/C++Basics/test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:2658: WarmUp/MovingOn/task/CMakeFiles/WarmUp-MovingOn-MoveAnObject-test.dir/rule] Error 2
make: *** [Makefile:988: WarmUp-MovingOn-MoveAnObject-test] Error 2

This is due to google-test < 1.11.0 failing to cleanly build with GCC >= 11. See https://github.com/google/googletest/issues/3219

This could be fixed by passing -Wno-error to cmake, patching the subdirectory with the closing commit on the issue linked above, or updating the google-test version.

Manually updating cmake/googletest-download.cmake to add release-1.11.0 fixes this issue for me.

eupp commented 1 year ago

Hi, thank you for the report. It is a known problem. The fix is already implemented, and the course will be soon updated on the Marketplace.