Skip to content

Suppress GCC -Weffc++ and -Wctor-dtor-privacy warnings in public headers#3090

Open
SNelcha wants to merge 1 commit into
catchorg:develfrom
SNelcha:suppress-gcc-warnings
Open

Suppress GCC -Weffc++ and -Wctor-dtor-privacy warnings in public headers#3090
SNelcha wants to merge 1 commit into
catchorg:develfrom
SNelcha:suppress-gcc-warnings

Conversation

@SNelcha
Copy link
Copy Markdown

@SNelcha SNelcha commented Apr 20, 2026

This pull request addresses warning leakage from Catch2 internals when users include Catch2 headers under strict compiler warning flags.
The change adds GCC-specific suppression macros for -Weffc++ and -Wctor-dtor-privacy in src/catch2/internal/catch_compiler_capabilities.hpp, and applies them at major public header boundaries so these warnings are contained within Catch2 rather than surfacing in downstream user builds.
The updated public entry headers are:
src/catch2/catch_test_macros.hpp
src/catch2/catch_template_test_macros.hpp
src/catch2/catch_session.hpp
src/catch2/catch_all.hpp
src/catch2/matchers/catch_matchers.hpp
src/catch2/generators/catch_generators.hpp
This is a minimal, boundary-based fix intended to align with Catch2’s existing warning suppression infrastructure rather than refactoring all internal warning-triggering patterns.
Validation performed:
cmake --build build succeeded
ctest --test-dir build --output-on-failure passed (75/75)
compile probes across the major public headers passed with -Weffc++ -Wctor-dtor-privacy -Werror in the local environment

@horenmar
Copy link
Copy Markdown
Member

horenmar commented May 7, 2026

If you have specific changes to propose I will look over them, but the Weffc++ implementation quality is too low to bother supporting it. See warnings like these:

class ScopedElement {
public:
    ScopedElement( XmlWriter* writer CATCH_ATTR_LIFETIMEBOUND, XmlFormatting fmt );

    ScopedElement( ScopedElement&& other ) noexcept;
    ScopedElement& operator=( ScopedElement&& other ) noexcept;
    ~ScopedElements();
    // ...
}; 
/mnt/c/ubuntu/Catch2/src/catch2/../catch2/internal/catch_xmlwriter.hpp: At global scope:
/mnt/c/ubuntu/Catch2/src/catch2/../catch2/internal/catch_xmlwriter.hpp:63:15: warning: ‘class Catch::XmlWriter::ScopedElement’ has pointer data members [-Weffc++]
   63 |         class ScopedElement {
      |               ^~~~~~~~~~~~~
/mnt/c/ubuntu/Catch2/src/catch2/../catch2/internal/catch_xmlwriter.hpp:63:15: warning:   but does not declare ‘Catch::XmlWriter::ScopedElement(const Catch::XmlWriter::ScopedElement&)’ [-Weffc++]
/mnt/c/ubuntu/Catch2/src/catch2/../catch2/internal/catch_xmlwriter.hpp:63:15: warning:   or ‘operator=(const Catch::XmlWriter::ScopedElement&)’ [-Weffc++]
/mnt/c/ubuntu/Catch2/src/catch2/../catch2/internal/catch_xmlwriter.hpp:93:24: note: pointer member ‘Catch::XmlWriter::ScopedElement::m_writer’ declared here
   93 |             XmlWriter* m_writer = nullptr;
      |                        ^~~~~~~~        

Oh the class doesn't declare copy operators? Duh, it has move operators. Similarly, the warning doesn't handle classes deriving from NonCopyable to disable copy/move ops.


Another example:

class MessageHolder {
    // The actual message vector passed to the reporters
    std::vector<MessageInfo> messages;
    // IDs of messages from UNSCOPED_X macros, which we have to
    // remove manually.
    std::vector<unsigned int> unscoped_ids;

    // ...
};
/mnt/c/ubuntu/Catch2/src/catch2/internal/catch_run_context.cpp: In constructor ‘Catch::Detail::MessageHolder::MessageHolder()’:
/mnt/c/ubuntu/Catch2/src/catch2/internal/catch_run_context.cpp:240:15: warning: ‘Catch::Detail::MessageHolder::messages’ should be initialized in the member initialization list [-Weffc++]
  240 |         class MessageHolder {
      |               ^~~~~~~~~~~~~
/mnt/c/ubuntu/Catch2/src/catch2/internal/catch_run_context.cpp:240:15: warning: ‘Catch::Detail::MessageHolder::unscoped_ids’ should be initialized in the member initialization list [-Weffc++]

No, I am not going to explicitly initialize std::vector, when it has perfectly good default initialization.

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 this pull request may close these issues.

2 participants