public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libobjc/53944] New: Can't catch C++ exception in Objective C
@ 2012-07-12 17:37 kostja.osipov at gmail dot com
2012-07-12 17:39 ` [Bug libobjc/53944] " kostja.osipov at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: kostja.osipov at gmail dot com @ 2012-07-12 17:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53944
Bug #: 53944
Summary: Can't catch C++ exception in Objective C
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libobjc
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kostja.osipov@gmail.com
There is no way with GCC runtime to catch a C++ exception in Objective C code.
The catch-all clause doesn't work.
At some point this limitation was documented, but later removed from the
manual.
Right now the code compiles, but fails to produce expected results.
kostja@atlas:~$ cat bar.cc
extern "C" int bar()
{
throw "exception";
}
kostja@atlas:~$ cat foo.m
#include <stdio.h>
extern int bar();
int main()
{
@try {
bar();
} @catch (...) {
printf("caught\n");
} @finally {
printf("finally\n");
}
}
kostja@atlas:~$ g++ -c -fexceptions bar.cc
kostja@atlas:~$ g++ -c -fexceptions -fobjc-exceptions foo.m
kostja@atlas:~$ g++ foo.o bar.o -lobjc
kostja@atlas:~$ ./a.out
terminate called after throwing an instance of 'char const*'
[1] 20822 abort (core dumped) ./a.out
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libobjc/53944] Can't catch C++ exception in Objective C
2012-07-12 17:37 [Bug libobjc/53944] New: Can't catch C++ exception in Objective C kostja.osipov at gmail dot com
@ 2012-07-12 17:39 ` kostja.osipov at gmail dot com
2012-07-12 18:23 ` steven at gcc dot gnu.org
2013-05-24 13:03 ` kostja.osipov at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: kostja.osipov at gmail dot com @ 2012-07-12 17:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53944
Konstantin Osipov <kostja.osipov at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Host| |Linux atlas
| |3.2.0-26-generic #41-Ubuntu
| |SMP Thu Jun 14 17:49:24 UTC
| |2012 x86_64 x86_64 x86_64
| |GNU/Linux
Version|unknown |4.6.3
Severity|normal |major
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libobjc/53944] Can't catch C++ exception in Objective C
2012-07-12 17:37 [Bug libobjc/53944] New: Can't catch C++ exception in Objective C kostja.osipov at gmail dot com
2012-07-12 17:39 ` [Bug libobjc/53944] " kostja.osipov at gmail dot com
@ 2012-07-12 18:23 ` steven at gcc dot gnu.org
2013-05-24 13:03 ` kostja.osipov at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: steven at gcc dot gnu.org @ 2012-07-12 18:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53944
--- Comment #1 from Steven Bosscher <steven at gcc dot gnu.org> 2012-07-12 18:23:33 UTC ---
Try obj-c++
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libobjc/53944] Can't catch C++ exception in Objective C
2012-07-12 17:37 [Bug libobjc/53944] New: Can't catch C++ exception in Objective C kostja.osipov at gmail dot com
2012-07-12 17:39 ` [Bug libobjc/53944] " kostja.osipov at gmail dot com
2012-07-12 18:23 ` steven at gcc dot gnu.org
@ 2013-05-24 13:03 ` kostja.osipov at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: kostja.osipov at gmail dot com @ 2013-05-24 13:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53944
--- Comment #2 from Konstantin Osipov <kostja.osipov at gmail dot com> ---
Objective C++ exception handling is broken in gcc completely, here's a small
example of trying to use C++ and Objective C exceptions together which
SEGFAULTs:
kostja@olah ~ % cat foo.mm
#include <stdio.h>
#include <stdlib.h>
#import <objc/runtime.h>
@interface Object {
Class isa;
}
+ (id) alloc;
- (id) init;
- (void) free;
@end
@implementation Object
+ (id) alloc
{
return class_createInstance(self, 0);
}
- (id) init
{
return self;
}
- (void) free
{
object_dispose(self);
}
@end
@interface Frob: Object
@end
@implementation Frob: Object
@end
int proc() {
@throw [[Frob alloc] init];
}
int foo()
{
@try {
return proc();
}
@catch (Frob *) {
printf("Catch(Frob *)\n");
return 0;
}
@catch (Object *) {
printf("Catch(Object *)\n");
return 0;
}
@catch (id) {
printf("Catch(id)\n");
return 0;
}
@catch (...) {
printf("Catch(...)\n");
return 0;
}
}
int main(void)
{
foo();
return 0;
}
kostja@olah ~ % g++ -fobjc-exceptions foo.mm -lobjc
kostja@olah ~ % ./a.out
zsh: segmentation fault (core dumped) ./a.out
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-05-24 13:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12 17:37 [Bug libobjc/53944] New: Can't catch C++ exception in Objective C kostja.osipov at gmail dot com
2012-07-12 17:39 ` [Bug libobjc/53944] " kostja.osipov at gmail dot com
2012-07-12 18:23 ` steven at gcc dot gnu.org
2013-05-24 13:03 ` kostja.osipov at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).