This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 26748


This patch fixes PR c++/26748, a crash on a static_cast to a type
specified as:

  float *__attribute__((...))

The claim in the PR is that this is valid code, but I do not believe
that to be a valid type ID.  The (GNU) C++ grammar permits attributes
before a direct-abstract-declarator, but there is no such declarator
here.  (A valid example would be "float *__attribute__((...)) [3]").

It might be that we should adjust the grammar in some way to
accomodate attributes here, but it is certainly better not to crash.
So, this patch makes the obvious change to avoid the ICE.  If we do
change the grammar, we should make sure that the C and C++ front-ends
agree on this point.

Tested on x86_64-unknown-linux-gnu, applied to the mainline.  I will
apply to 4.1 after tests complete.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-06-14  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27648
	* parser.c (cp_parser_declarator): Robustify.

2006-06-14  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27648
	* g++.dg/ext/attrib22.C: New test.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 114635)
+++ gcc/cp/parser.c	(working copy)
@@ -11283,7 +11280,7 @@ cp_parser_declarator (cp_parser* parser,
 						member_p);
     }
 
-  if (attributes && declarator != cp_error_declarator)
+  if (attributes && declarator && declarator != cp_error_declarator)
     declarator->attributes = attributes;
 
   return declarator;
Index: gcc/testsuite/g++.dg/ext/attrib22.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attrib22.C	(revision 0)
+++ gcc/testsuite/g++.dg/ext/attrib22.C	(revision 0)
@@ -0,0 +1,6 @@
+// PR c++/27648
+
+void f()
+{
+  static_cast<float *__attribute((unused))>(0); // { dg-error "expected" }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]