Bug 112471 - catch handler of type "reference to array" should be unreachable, but is reached
Summary: catch handler of type "reference to array" should be unreachable, but is reached
Status: RESOLVED DUPLICATE of bug 69372
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: EH
Depends on:
Blocks:
 
Reported: 2023-11-10 04:14 UTC by Arthur O'Dwyer
Modified: 2023-11-10 04:30 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***