Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -676,10 +676,45 @@ AC_SUBST(TESTS_STATIC_LIB, tests.a) TESTS_LIBS="$TESTS_LIBS -framework CoreFoundation" ]) ;; esac + +AC_MSG_CHECKING(whether Objective C compiler supports ARC) +old_OBJCFLAGS="$OBJCFLAGS" +OBJCFLAGS="$OBJCFLAGS -fobjc-arc -fobjc-arc-exceptions" +AC_TRY_COMPILE([ + #ifdef __has_attribute + # if __has_attribute(objc_root_class) + __attribute__((__objc_root_class__)) + # endif + #endif + @interface Foo + { + struct objc_class *_isa; + } + + + (id)alloc; + @end + + @implementation Foo + + (id)alloc + { + return (id)0; + } + @end +], [ + __weak id foo = [Foo alloc]; + (void)foo; +], [ + AC_MSG_RESULT(yes) + AC_DEFINE(COMPILER_SUPPORTS_ARC, 1, [Whether the compiler supports ARC]) + AC_SUBST(RUNTIME_ARC_TESTS_M, RuntimeARCTests.m) +], [ + AC_MSG_RESULT(no) +]) +OBJCFLAGS="$old_OBJCFLAGS" AC_C_BIGENDIAN([ AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian]) ]) AS_IF([test x"$ac_cv_c_bigendian" = x"universal"], [ Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -64,10 +64,11 @@ OF_SCTP_SOCKET_M = @OF_SCTP_SOCKET_M@ OF_SELECT_KERNEL_EVENT_OBSERVER_M = @OF_SELECT_KERNEL_EVENT_OBSERVER_M@ REEXPORT_RUNTIME = @REEXPORT_RUNTIME@ REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@ RUNTIME = @RUNTIME@ +RUNTIME_ARC_TESTS_M = @RUNTIME_ARC_TESTS_M@ RUNTIME_AUTORELEASE_M = @RUNTIME_AUTORELEASE_M@ RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@ RUNTIME_INSTANCE_M = @RUNTIME_INSTANCE_M@ RUNTIME_LIBS = @RUNTIME_LIBS@ RUN_TESTS = @RUN_TESTS@ Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -36,10 +36,11 @@ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ PBKDF2Tests.m \ RuntimeTests.m \ + ${RUNTIME_ARC_TESTS_M} \ ScryptTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ @@ -201,8 +202,9 @@ ${PROG_NOINST}.3dsx: ${PROG_NOINST} 3dsxtool $< $@ CPPFLAGS += -I../src -I../src/exceptions -I../src/runtime -I.. -DSTDOUT +OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions LIBS := ${TESTS_LIBS} ${LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} ADDED tests/RuntimeARCTests.m Index: tests/RuntimeARCTests.m ================================================================== --- tests/RuntimeARCTests.m +++ tests/RuntimeARCTests.m @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019, 2020 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "TestsAppDelegate.h" + +static OFString *module = @"Runtime (ARC)"; + +@interface RuntimeARCTest: OFObject +@end + +@implementation RuntimeARCTest +- (instancetype)init +{ + self = [super init]; + + @throw [OFException exception]; + + return self; +} +@end + +@implementation TestsAppDelegate (RuntimeARCTests) +- (void)runtimeARCTests +{ + id object; + + EXPECT_EXCEPTION(@"Exceptions in init", OFException, + object = [[RuntimeARCTest alloc] init]) +} +@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -175,10 +175,14 @@ @end @interface TestsAppDelegate (RuntimeTests) - (void)runtimeTests; @end + +@interface TestsAppDelegate (RuntimeARCTests) +- (void)runtimeARCTests; +@end @interface TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -312,10 +312,13 @@ [[OFFileManager defaultManager] changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self runtimeTests]; +#ifdef COMPILER_SUPPORTS_ARC + [self runtimeARCTests]; +#endif [self objectTests]; [self methodSignatureTests]; [self invocationTests]; [self forwardingTests]; #ifdef OF_HAVE_BLOCKS