]> granicus.if.org Git - clang/commitdiff
implement some more FIXMEs, by rejecting more bogus stuff in
authorChris Lattner <sabre@nondot.org>
Sun, 26 Oct 2008 23:29:41 +0000 (23:29 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Oct 2008 23:29:41 +0000 (23:29 +0000)
objc mode.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58216 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseInit.cpp
test/Parser/objc-init.m

index f4d18fbb4cf507051744e64eddc59aeb76a1a2b9..655d8e75c729be6e4d148745b7cba7d17eca390c 100644 (file)
@@ -121,8 +121,18 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
     // If Objective-C is enabled and this is a typename or other identifier
     // receiver, parse this as a message send expression.
     if (getLang().ObjC1 && isTokObjCMessageIdentifierReceiver()) {
-      // FIXME: Emit ext_gnu_missing_equal_designator for inits like
-      // [4][foo bar].
+      // If we have exactly one array designator, this used the GNU
+      // 'designation: array-designator' extension, otherwise there should be no
+      // designators at all!
+      if (Desig) {
+        if (Desig->getNumDesignators() == 1 && 
+            (Desig->getDesignator(0).isArrayDesignator() ||
+             Desig->getDesignator(0).isArrayRangeDesignator()))
+          Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
+        else
+          Diag(Tok, diag::err_expected_equal_designator);
+      }
+      
       IdentifierInfo *Name = Tok.getIdentifierInfo();
       ConsumeToken();
       return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, Name, 0);
@@ -143,8 +153,19 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
     // an assignment-expression production.
     if (getLang().ObjC1 && Tok.isNot(tok::ellipsis) && 
         Tok.isNot(tok::r_square)) {
-      // FIXME: Emit ext_gnu_missing_equal_designator for inits like
-      // [4][foo bar].
+      
+      // If we have exactly one array designator, this used the GNU
+      // 'designation: array-designator' extension, otherwise there should be no
+      // designators at all!
+      if (Desig) {
+        if (Desig->getNumDesignators() == 1 && 
+            (Desig->getDesignator(0).isArrayDesignator() ||
+             Desig->getDesignator(0).isArrayRangeDesignator()))
+          Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
+        else
+          Diag(Tok, diag::err_expected_equal_designator);
+      }
+      
       return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
     }
 
index 4478665f7accd65f3a2593174212d66e72072085..085db7256898c536e54c577f3b727818feb846ba 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify %s -pedantic
 // rdar://5707001
 
 @interface NSNumber;
@@ -6,6 +6,10 @@
 - (unsigned) METH2;
 @end
 
+struct SomeStruct {
+  int x, y, z, q;
+};
+
 void test1() {
        id objects[] = {[NSNumber METH]};
 }
@@ -24,3 +28,14 @@ void test4() {
   unsigned x[] = {[NSNumber METH2]+2};
 }
 
+void test5(NSNumber *x) {
+  unsigned y[] = {
+    [4][NSNumber METH2]+2,   // expected-warning {{use of GNU 'missing =' extension in designator}}
+    [4][x METH2]+2   // expected-warning {{use of GNU 'missing =' extension in designator}}
+  };
+  
+  struct SomeStruct z = {
+    .x = [x METH2], // ok.
+    .x [x METH2]    // expected-error {{expected '=' or another designator}}
+  };
+}