https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112471
Bug ID: 112471 Summary: catch handler of type "reference to array" should be unreachable, but is reached Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arthur.j.odwyer at gmail dot com Target Milestone: --- // https://godbolt.org/z/W9P6GrG4x #include <stdio.h> int main() { try { throw nullptr; } catch (const int(&)[2]) { puts("caught int(&)[2]"); } catch (const int*) { puts("caught int*"); } } The correct output is "caught int*", because nullptr is not an array. Clang and EDG produce the correct output. MSVC is so confident that you can't throw an array (I think they're right!) that it diagnoses the `catch` at -W4: // https://godbolt.org/z/v6M1e5ff5 warning C4843: 'const int (&)[2]': An exception handler of reference to array or function type is unreachable, use 'const int *' instead GCC also mishandles unreachable catch handlers of type "reference to function": again the correct output is "caught int*", Clang/EDG/MSVC all get it right, and MSVC diagnoses. // https://godbolt.org/z/sqoW6cPTn try { throw nullptr; } catch (int(&)()) { puts("caught int(&)()"); } catch (const int*) { puts("caught int*"); }