This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug objc/67455] New: Inheriting from Object doesn't provide alloc, init or new rendering methods usless
- From: "jam.hobson at hotmail dot co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 05 Sep 2015 01:08:20 +0000
- Subject: [Bug objc/67455] New: Inheriting from Object doesn't provide alloc, init or new rendering methods usless
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67455
Bug ID: 67455
Summary: Inheriting from Object doesn't provide alloc, init or
new rendering methods usless
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: objc
Assignee: unassigned at gcc dot gnu.org
Reporter: jam.hobson at hotmail dot co.uk
Target Milestone: ---
I have selected version 4.8.1, but other versions have the same problem
When ever I try to instantiate a class using ClassName *foo = [[ClassName
alloc] init]; or ClassName *foo = [ClassName new]; it tells me that +alloc and
-init or -new don't exist. Other people on the internet are having the same
issues
I know that the objc part of GCC has been updated, the bug may be that there
are no updated documents detailing how to use the new version without using
GNUStep or another runtime.
here is an example of the problem:
code:
#import <stdlib.h>
#import <objc/Object.h>
@interface TestObject : Object
{
int internalInt;
}
- (int)add:(int)anInt;
- (int)subtract:(int)anInt;
- (int)value;
@end
@implementation TestObject
- (id)init
{
if ((self = [super init]))
{
internalInt = 0;
}
return self;
}
- (int)add:(int)anInt
{
internalInt += anInt;
return internalInt;
}
- (int)subtract:(int)anInt
{
internalInt -= anInt;
return internalInt;
}
- (int)value
{
return internalInt;
}
@end
int main(int argc, char** argv)
{
TestObject *aTestObject = [[TestObject alloc] init];
printf("Initial Value: %d\n", [aTestObject value]);
printf("+45 Value: %d\n", [aTestObject add: 45]);
printf("-63 Value: %d\n", [aTestObject subtract: 63]);
[aTestObject add: 103];
printf("+103 Value: %d\n", [aTestObject value]);
return (EXIT_SUCCESS);
}
debug error:
gcc -o main main.m -lobjc
main.m: IN function '-{TestObject init]':
main.m:20:2: warning: 'Object' may not respond to '-init' [enabled by default]
if ((self = [super init]))
^
main.m:20:2: warning: (Messages without a matching method signature [enabled by
default]
main.m:20:2: warning will be assumed to return 'id' and accept [enabled by
default]
main.m:20:2: warning: '...' as arguments.) [enabled by default]
main.m: In function 'main':
TestObject *aTestObject = [[TestObject alloc] init];
^
main.m:51:2: warning: incompatible implicit declaration of built-in function
'printf' [enabled by default]
printf("Initial Value: %d\n", [aTestObject value]);
^
Please help!