Skip to content

Commit e6cbbe9

Browse files
committed
test: Add a test for catching pointers by reference
This test should make sure that #522 doesn't regress again.
1 parent 035a464 commit e6cbbe9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ TESTS_C_NO_BUILTIN = crt-test
7070
TESTS_C_ANSI_STDIO = crt-test
7171
TESTS_C_AS_CPP = crt-test
7272
TESTS_CPP = hello-cpp global-terminate tlstest-main longjmp-cleanup
73-
TESTS_CPP_EXCEPTIONS = hello-exception exception-locale exception-reduced
73+
TESTS_CPP_EXCEPTIONS = hello-exception exception-locale exception-reduced exception-catch-ptr-ref
7474
TESTS_CPP_STATIC = hello-exception
7575
TESTS_CPP_DLL = tlstest-lib throwcatch-lib
7676
TESTS_CPP_LINK_DLL = throwcatch-main

test/exception-catch-ptr-ref.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025 Martin Storsjo
3+
*
4+
* This file is part of llvm-mingw.
5+
*
6+
* Permission to use, copy, modify, and/or distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include <stdio.h>
20+
#include <string.h>
21+
22+
int main(int argc, char* argv[]) {
23+
try {
24+
const char *e = "EX";
25+
printf("throwing e %p &e %p\n", e, &e);
26+
throw e;
27+
} catch (const char* &e) {
28+
printf("caught e %p &e %p\n", e, &e);
29+
printf("e=%s\n", e);
30+
if (strcmp(e, "EX")) {
31+
printf("Incorrect string pointer reference caught!\n");
32+
return 1;
33+
}
34+
}
35+
return 0;
36+
}

0 commit comments

Comments
 (0)