Prevent `-Weffc++` and `-W-ctor-dtor-privacy` warnings from leaking out
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cmake, cpp
- Domain
- build-system, testing-qa
Research direction
Start by reproducing the GCC 13.3.0 build with the listed Catch2 headers, then inspect how the Catch2 include targets and headers are exposed through CMake FetchContent. The work is done when -Weffc++ and -W-ctor-dtor-privacy warnings no longer leak from Catch2 while consumer diagnostics remain effective.
Written by the indexing model from the issue text.
Description
Description
I updated Catch2 used in my project from some old Catch2v2 version to v3. When including Catch2 in my project tests through the CMake fetcher as a dependency, compiling the project with Clang (clang 17.0.6) does not issue any warnings, but compiling with GCC (g++ 13.3.0) issues a number of -Weffc++ and -W-ctod-dtor-privacy warnings.
I presume the code in Catch2 is supposed to behave as it does. Therefore, suppressing these warnings on a per-header file level should be the correct answer (or anything similar to this) to removing these warnings, while still allowing the users of Catch2 to include specific header files with the warnings set up for their tests source code.
Steps to reproduce
CMake snippet:
if (BUILD_TESTING)
# Catch2 library for writing tests
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.7.1
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib)
include(Catch)
endif()
target_link_libraries(tests PRIVATE <project files> Catch2::Catch2WithMain)
Tests source C++ file:
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
// Tests.
Additional context
Generated warnings:
- (binary)
user-defined <some class>::operator ... always evaluates both arguments, all member functions in class <some class> are private,<some class> has pointer data members ... but does not declare ...,- ...
Log of the build process: warnings.txt.
Suggested alternative
There are a number of options to suppress these warnings.
Manually, each user can disable the warnings for each test source file, for example by wrapping the includes of Catch2 headers in pragmas:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#pragma GCC diagnostic pop
I also managed to suppress the warnings on a per-project basis by setting the Catch2 library as a system library in CMake: (include inside the above-mentioned CMake code after the line include(Catch)):
get_target_property(catch2_includes Catch2 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(Catch2 SYSTEM INTERFACE ${catch2_includes})
Nevertheless, I think that the preferred approach would be to suppress these warnings on the Catch2 side once and for all (whichever approach is chosen), as opposed to forcing each user of Catch2 to suppress the warnings manually in their projects.
Related issues
https://github.com/catchorg/Catch2/issues/208
https://github.com/catchorg/Catch2/issues/407
- Dominant language
- C++
- Stars
- 21.6k
- Forks
- 3.4k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from catchorg/Catch2
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
catch_discover_tests passes all EXTRA_ARGS as one argumentPossibly taken @CyberKun claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
catchorg/Catch2#3239 · 1 comment ·
Maintainers usually reply within 2 days
-
Not seeing some error messages from fakeit in jetbrains riderPossibly taken @Amanpal9 claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
catchorg/Catch2#3228 · 1 comment ·
Maintainers usually reply within 2 days
-
catch_discover_tests fails for Emscripten/WASM tests since v3.16.0Possibly taken @nafiurahman00 claimed this 8 days ago. OpenExtras
Difficulty 3/5 1-2 days Newbie friendliness 72/100
catchorg/Catch2#3241 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cp-algorithms/cp-algorithms#1774 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
telefonicaid/fiware-orion#4836 ·
Maintainers usually reply within 1 day
-
nixd exits at startup when its parent process belongs to another userPossibly taken @conao3 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nix-community/nixd#930 ·
Maintainers usually reply within 2 days
-
refactor topic-ui topic-weather
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Command-Install Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
microsoft/winget-cli#6718 ·
Maintainers usually reply within 2 days