http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47231

           Summary: Commas inside ObjC method invocation can confuse
                    compiler
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: objc
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: nic...@gcc.gnu.org


GCC accepts the invalid code

 [receiver firstArgument: a, b secondArgument: c];

and seems to (mis)compile it as if 

 [receiver firstArgument:a  secondArgument: b];

had been typed.

This is not a regression; it seems that GCC has always behaved like that (which
also suggests it's not such a high priority since nobody ever noticed or
reported it; presumably few people accidentally put commas in there).

I tried out clang 2.8, and it rejects the invalid syntax; we should improve
GCC to reject it too! ;-)

Here is a more complete testcase, with the lines that have undetected syntax
errors marked --

/* Contributed by Nicola Pero <nicola.p...@meta-innovation.com>, January 2011. 
*/
/* { dg-do compile } */

@interface MyClass
- (void) method: (id)x;
- (void) method2: (id)x : (id)y;
@end

void test (MyClass *o)
{
  [o method:];      /* { dg-error "syntax error" } */
  [o method: o];    /* Ok */
  [o method: o, o]; /* { dg-error "too many arguments" } */

  [o method2::];           /* { dg-error "syntax error" } */
  [o method2: o :];        /* { dg-error "syntax error" } */
  [o method2: o, o :];     /* { dg-error "syntax error" } */
  [o method2: o, o :o];    /* { dg-error "too many arguments" } */ /* Missing
error */
  [o method2: o    :o];    /* Ok */
  [o method2: o, o :o, o]; /* { dg-error "too many arguments" } */ /* Missing
error */
  [o method2: o    :o, o]; /* { dg-error "too many arguments" } */
}

Thanks

Reply via email to