Bug 112471

Summary: catch handler of type "reference to array" should be unreachable, but is reached
Product: gcc Reporter: Arthur O'Dwyer <arthur.j.odwyer>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal Keywords: EH
Priority: P3    
Version: 14.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96119
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69372
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Arthur O'Dwyer 2023-11-10 04:14:38 UTC
// 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*");
    }
Comment 1 Andrew Pinski 2023-11-10 04:29:10 UTC
I think this is a dup of bug 69372.
Comment 2 Andrew Pinski 2023-11-10 04:30:15 UTC
It is a dup of bug 69372.

*** This bug has been marked as a duplicate of bug 69372 ***