public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: John Holdsworth <mac@johnholdsworth.com>
To: John Holdsworth <mac@johnholdsworth.com>
Cc: gcc@gnu.org
Subject: Bus error gcc compiler for any for ( x in array ) inside Objective-C++ template
Date: Thu, 15 Oct 2009 09:32:00 -0000	[thread overview]
Message-ID: <E790715F-2067-44DE-A1DC-1CFEFE9FF48F@johnholdsworth.com> (raw)
In-Reply-To: <4A7E26EB-B9BA-499F-9827-146BF7CC496F@johnholdsworth.com>


Hi,

I've encountered a bus error using Apple's gcc in Xcode 3.1, 3.2
compiling  the following code or any containing for( x in y ) is used
inside a template in Objective-C++.

template <typename ETYPE>
class OODictionary {
	void boom() {
		NSArray *keys = nil;
		for ( NSString *key in keys ) {
		}
	}
};

I've not been able to build with a more recent gcc so I can't tell
if it is still present but figure I'd better let you guys know.

Thanks,

John H.
http://objcpp.johnholdsworth.com


On 8 Sep 2009, at 21:30, John Holdsworth wrote:

> Hi,
>
> I've found it very useful to be able to use C++ to extend Objective-C
> using a little judicious operator overloading and I notice that  
> gcc-4.2
> now automatically "unboxes" wrapper classes with no warning when
> they are messaged - provided an appropriate cast is available.
>
> For example:
>
> class AStringClass {
> 	NSMutaableString *str;
> public:
>  	AStringClass( NSMutableString *str ) {
> 		this->str = str;
> 	}
> 	operator NSMutableString * () {
> 		return str;
> 	}
> };
>
> This class can now be messaged in gcc4.2 as below without a warning:
>
> 	AStringClass aString( nil );
> 	[aString doubleValue];
>
> Unfortunately is can also be sent a message which the compiler
> is in a position to know is not available given the only cast
> available was to a NSMutableString:
>
> 	[aString count]; // not a valid method for NSMutableString *
>
> This happens as internally as there is an implicit cast to type "id"  
> in
> ${GCCROOT}gcc/objc/objc-act,c, function: objc_finish_message_expr
>
> 	  /* APPLE LOCAL begin decay function/array receivers */
> #ifndef OBJCPLUS
> 	  /* In C need to decay array/function receivers so can be converted
> 	     to id. */
> 	  struct c_expr exp;
> 	  exp.value = receiver;
> 	  exp = default_function_array_conversion (exp);
> 	  receiver = exp.value;
> 	/* APPLE LOCAL begin radar 3533972 */
> #else
> 	  if (can_convert_arg (objc_object_type, TREE_TYPE (receiver),
> 				receiver, LOOKUP_NORMAL))
> 	    {
> 	      /* In rare cases, 'receiver' must be converted to type 'id'  
> using
> 	         user-defined type conversion. 'id' is type of the 1st  
> argument to
> 	         objc_msgSend (id self, SEL op, ...); */
> 	      tree cnv_rec = perform_implicit_conversion (objc_object_type,  
> receiver);
>              if (cnv_rec && cnv_rec != error_mark_node)
> 	        return objc_finish_message_expr (cnv_rec, sel_name,  
> method_params);
> 	    }
> 	/* APPLE LOCAL end radar 3533972 */
> #endif
>
> Would it not be possible for the implicit conversion retain the type
> which it was forced into using when searching for a match for "id"
> and using this as the type of the receiver of the message rather
> than "id". I've looked and the code but can't quite get to where
> the change (probably quite a small one) would need to be made.
> Perhaps even, this is already fixed...
>
> Can anybody help?
>
> John Holdsworth
> objcpp.johnholdsworth.com
>
>
> On 8 Apr 2009, at 14:34, David Ayers wrote:
>
>> Am Samstag, den 21.03.2009, 11:59 +0100 schrieb John Holdsworth:
>>
>>> I was wondering if it would be a useful extension to Objective-C
>>> expand the [] operator
>>> to support array and hash references to NSArray and NSDictionary
>>> classes directly to
>>> greatly improve the readability of code:
>>
>> I'm not an ObjC front end maintainer and have no authority but one  
>> issue
>> I would have with this feature with gcc proper is that the ObjC front
>> end would have to learn about the semantics of "NSArray" and
>> "NSDictionary" which are actually not part of the language but part  
>> of
>> an external library.
>>
>> Now gcc already supports the -fconstant-string-class option as one  
>> way
>> to embed knowledge about an external library into an executable.   
>> But I
>> would like adding options with all these semantics from a foreign
>> library into the language implementation.
>>
>> Maybe this could be done more elegantly with plugin infrastructure  
>> that
>> that es being currently added: http://gcc.gnu.org/wiki/plugins
>>
>> Cheers,
>> David
>>
>>

  reply	other threads:[~2009-10-15  7:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-08 19:30 Minor problem messaging C++ wrappers in Objective-C with gcc4.2 John Holdsworth
2009-10-15  9:32 ` John Holdsworth [this message]
2009-10-15 22:42   ` Bus error gcc compiler for any for ( x in array ) inside Objective-C++ template Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E790715F-2067-44DE-A1DC-1CFEFE9FF48F@johnholdsworth.com \
    --to=mac@johnholdsworth.com \
    --cc=gcc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).