diff mbox

ObjC++: fix for objc++/46222

Message ID 1290857130.906113251@192.168.2.228
State New
Headers show

Commit Message

Nicola Pero Nov. 27, 2010, 11:25 a.m. UTC
This patch fixes objc++/46222.  It's an ICE triggered by pathologically invalid
ObjC++ code where someone is using a function declaration as a property declaration.
The fix simply replaces the assert that causes the ICE with a check that prints
an error message and returns error_mark_node.  I tried to use an error message
that would make sense in C++ as well if that check is ever hit in C++.  Even in
C++, if the check/assert is ever triggered it would be much better to print an error
message and continue than to suddenly ICE.

Ok to commit ?

Thanks

Comments

Mike Stump Nov. 27, 2010, 4:52 p.m. UTC | #1
On Nov 27, 2010, at 3:25 AM, "Nicola Pero" <nicola.pero@meta-innovation.com> wrote:
> This patch fixes objc++/46222.  It's an ICE triggered by pathologically invalid
> ObjC++ code

> Ok to commit ?

Ok.
>
diff mbox

Patch

Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (revision 167197)
+++ testsuite/ChangeLog (working copy)
@@ -1,5 +1,10 @@ 
 2010-11-27  Nicola Pero  <nicola.pero@meta-innovation.com>
 
+       PR objc++/46222 
+       * obj-c++.dg/property/at-property-2.mm: Uncommented testcase.
+
+2010-11-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
        * objc.dg/property/at-property-24.m: New.
        * objc.dg/property/at-property-25.m: New.       
        * obj-c++.dg/property/at-property-24.mm: New.
Index: testsuite/obj-c++.dg/property/at-property-2.mm
===================================================================
--- testsuite/obj-c++.dg/property/at-property-2.mm      (revision 167195)
+++ testsuite/obj-c++.dg/property/at-property-2.mm      (working copy)
@@ -8,7 +8,6 @@ 
 }
 @property int name __attribute__((deprecated));
 @property int table __attribute__((xxx));       /* { dg-warning ".xxx. attribute directive ignored" } */
-/* FIXME: the test below should not ICE.
-@property void function (void);                  { dg-error "can.t make .function. into a method" } */
+@property void function (void);                 /* { dg-error "declaration of function .function. in invalid context" } */
 @property typedef int j;                        /*  { dg-error "invalid type for property" } */
 @end
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 167195)
+++ cp/decl.c   (working copy)
@@ -9531,7 +9531,21 @@  grokdeclarator (const cp_declarator *declarator,
 
            if (friendp == 0)
              {
-               gcc_assert (ctype);
+               /* This should never happen in pure C++ (the check
+                  could be an assert).  It could happen in
+                  Objective-C++ if someone writes invalid code that
+                  uses a function declaration for an instance
+                  variable or property (instance variables and
+                  properties are parsed as FIELD_DECLs, but they are
+                  part of an Objective-C class, not a C++ class).
+                  That code is invalid and is caught by this
+                  check.  */
+               if (!ctype)
+                 {
+                   error ("declaration of function %qD in invalid context",
+                          unqualified_id);
+                   return error_mark_node;
+                 }
 
                /* ``A union may [ ... ] not [ have ] virtual functions.''
                   ARM 9.5 */
Index: cp/ChangeLog
===================================================================
--- cp/ChangeLog        (revision 167195)
+++ cp/ChangeLog        (working copy)
@@ -1,3 +1,11 @@ 
+2010-11-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       PR objc++/46222
+       * decl.c (grokdeclarator): Replaced an assert (for a case that can
+       never happen in C++, but could happen in ObjC++ for invalid code)
+       with a check that prints an error message and returns
+       error_mark_node.
+
 2010-11-23  Jeffrey Yasskin <jyasskin@google.com>
 
        PR c++/46527