This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug objc/77481] New: @finally not executed if exception not caught or rethrown
- From: "vries at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 05 Sep 2016 09:34:18 +0000
- Subject: [Bug objc/77481] New: @finally not executed if exception not caught or rethrown
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77481
Bug ID: 77481
Summary: @finally not executed if exception not caught or
rethrown
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: objc
Assignee: unassigned at gcc dot gnu.org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
Consider finally.m, testing 4 scenarios:
1. no exception
2. caught exception
3. uncaught exception
4. rethrown exception
finally.m:
...
#import <objc/Object.h>
#import <stdio.h>
#if F == 1
int
main (void)
{
id o = nil;
@try {
printf ("trying\n");
} @catch (id ue) {
printf ("catching id\n");
} @finally {
printf ("finalizing\n");
}
printf ("done\n");
return 0;
}
#endif
#if F == 2
int
main (void)
{
id o = nil;
@try {
printf ("trying\n");
@throw o;
} @catch (id ue) {
printf ("catching id\n");
} @finally {
printf ("finalizing\n");
}
printf ("done\n");
return 0;
}
#endif
#if F == 3
int
main (void)
{
id o = nil;
@try {
printf ("trying\n");
@throw o;
} @catch (Object *ue) {
printf ("catching id\n");
} @finally {
printf ("finalizing\n");
}
printf ("done\n");
return 0;
}
#endif
#if F == 4
int
main (void)
{
id o = nil;
@try {
printf ("trying\n");
@throw o;
} @catch (id ue) {
printf ("catching id\n");
@throw;
} @finally {
printf ("finalizing\n");
}
printf ("done\n");
return 0;
}
#endif
...
Executing with gcc gives:
...
$ for n in $(seq 1 4); do echo executing case $n; gcc -DF=$n finally.m
-fobjc-exceptions -lobjc -static && ./a.out ; echo $?; echo ; done
executing case 1
trying
finalizing
done
0
executing case 2
trying
catching id
finalizing
done
0
executing case 3
trying
Aborted (core dumped)
134
executing case 4
trying
catching id
Aborted (core dumped)
134
...
As we can see, in the cases of the uncaught and rethrown exception, finally is
not executed.
If we try the same with clang, we see that finally is executed in all four
cases:
...
$ for n in $(seq 1 4); do echo executing case $n; clang finally.m -lobjc
-fobjc-exceptions -static -fexceptions -DF=1 $n && ./a.out; echo $? ; echo;
done
executing case 1
trying
finalizing
done
0
executing case 2
trying
catching id
finalizing
done
0
executing case 3
trying
finalizing
Aborted (core dumped)
134
executing case 4
trying
catching id
finalizing
Aborted (core dumped)
134
...