gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Diff to make core compile with gcc-4.1 prerelease


From: David Ayers
Subject: Re: Diff to make core compile with gcc-4.1 prerelease
Date: Fri, 07 Oct 2005 10:20:56 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050817)

Gregory John Casamento schrieb:
> Please find the attached patch.
> 
> Basically, it just coerces all of the problem places to id prior to coercing 
> it
> to GSIMapVal/GSIMapKey/etc.  This fixes the problem, but I'm not sure it's the
> cleanest solution.
> 
> I ran a test recently on gcc 3.4.3, using the attached simple test.c program. 
>  
> I got the following:
> 
> address@hidden heron]$ gcc -o testa test.c 
> test.c: In function `main':
> test.c:16: error: cast to union type from type not present in union

H'm...

> 
> #include <stdio.h>
> 
> typedef union {
>   int x;
>   void *y;
> } test_union;
> 
> void foo(test_union a)
> {
>   puts("here");
> }
> 
> int main(char *argv[], int argc)
> {
>   long a = 1024; // somevalue...
>   foo((test_union)a);
> 

but this is not what we are doing, as long and int are distinct types.
As you noticed this would have been an error in previous versions of GCC.

In our case there are the special ObjC semantics that any objects could
be matched to 'id'.  And even if 'id' were not present and only
"NSObject *" were, then the compiler should use that for any
identifiable subclass of NSObject.

I would tend to agree with Richard that this is a compiler bug and maybe
we should add something like the attached test case to gcc...

Andrew?

Cheers,
David

/* Contributed by David Ayers */
#include <objc/objc.h>
#include <objc/Object.h>

/* Test type checking with unions containing objc types as members.  */

@interface MySuperObject : Object
@end
@implementation MySuperObject
@end

@interface MyObject : MySuperObject
@end
@implementation MyObject
@end

typedef union
{
  id  o;
  SEL s;
} idu;

typedef union
{
  MyObject  *o;
  SEL        s;
} obju;

void foo_id (idu u)
{
}
void foo_obj (obju u)
{
}

int main (void)
{
  id             vo_i = nil;
  MyObject      *vo_o = nil;
  MySuperObject *vo_s = nil;

  foo_id ((idu)vo_i);
  foo_id ((idu)vo_o);
  foo_id ((idu)vo_s);

  foo_obj ((obju)vo_i);
  foo_obj ((obju)vo_o);
  foo_obj ((obju)vo_s); /* { dg-error "cast to union type from type not present 
in union" } */

  return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]