https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675
Bug ID: 97675 Summary: GCC does not allow turning off the warning for exceptions being caught by an earlier handler Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ldionne.2 at gmail dot com Target Milestone: --- In the LLVM libc++abi test suite, we test that an exception of type 'Child' is being caught by an earlier handler of type 'Base'. As a result, GCC (and Clang) produce a warning saying that the later catch clause (of type 'Child') will never be used. This is fine. However, Clang allows turning off that specific warning using -Wno-exceptions (or the appropriate warning pragma). GCC doesn't provide that option, which is problematic because we compile our test suite with -Werror. The options that are left are: - To disable these tests with GCC altogether - To disable -Werror on these tests Instead, it would be nice if GCC allowed controlling that warning (and perhaps other related warnings I'm not aware of) using a compiler flag. Reproducer: cat <<EOF | g++ -xc++ - -fsyntax-only struct Base { }; struct Child : Base { }; int main() { try { throw Child(); } catch (Base const&) { } catch (Child const&) { } } EOF Output: <stdin>: In function 'int main()': <stdin>:6:5: warning: exception of type 'Child' will be caught <stdin>:5:5: warning: by earlier handler for 'Base' Expectation: Some warning flag (e.g. -Wno-exceptions) allows turning off that warning.