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]

[patch] Fix PR c++/28249: "long long long" accepted by catch


The C++ frontend accepts invalid code like the following since GCC 4.0.3:

  void foo()
  {
    try {}
    catch (long long long) {}
  }

This was caused by the patch for PR c++/26151 that moved the checks
for duplicate decl_specifiers from grokdeclarator into the parser,
namely into cp_parser_decl_specifier_seq. Alas the checks are also
needed in cp_parser_type_specifier_seq.

The following patch fixes this by moving the checks into a seperate
function (cp_parser_check_decl_spec) and calls it from
cp_parser_decl_specifier_seq and cp_parser_type_specifier_seq.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch.

Regards,
Volker

:ADDPATCH C++:


2006-07-14  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28249
	* parser (cp_parser_check_decl_spec): New function.
	(cp_parser_decl_specifier_seq): Factor out check for repeated
        decl-specifiers into cp_parser_check_decl_spec. Use it.
	(cp_parser_type_specifier_seq) Use it.

===================================================================
--- gcc/gcc/cp/parser.c	(revision 115431)
+++ gcc/gcc/cp/parser.c	(working copy)
@@ -1950,6 +1950,49 @@ cp_parser_simulate_error (cp_parser* parser)
   return false;
 }
 
+/* Check for repeated decl-specifiers.  */
+
+static void
+cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs)
+{
+  cp_decl_spec ds;
+
+  for (ds = ds_first; ds != ds_last; ++ds)
+    {
+      unsigned count = decl_specs->specs[(int)ds];
+      if (count < 2)
+	continue;
+      /* The "long" specifier is a special case because of "long long".  */
+      if (ds == ds_long)
+	{
+	  if (count > 2)
+	    error ("%<long long long%> is too long for GCC");
+	  else if (pedantic && !in_system_header && warn_long_long)
+	    pedwarn ("ISO C++ does not support %<long long%>");
+	}
+      else if (count > 1)
+	{
+	  static const char *const decl_spec_names[] = {
+	    "signed",
+	    "unsigned",
+	    "short",
+	    "long",
+	    "const",
+	    "volatile",
+	    "restrict",
+	    "inline",
+	    "virtual",
+	    "explicit",
+	    "friend",
+	    "typedef",
+	    "__complex",
+	    "__thread"
+	  };
+	  error ("duplicate %qs", decl_spec_names[(int)ds]);
+	}
+    }
+}
+
 /* This function is called when a type is defined.  If type
    definitions are forbidden at this point, an error message is
    issued.  */
@@ -7376,7 +7420,6 @@ cp_parser_decl_specifier_seq (cp_parser*
 			      int* declares_class_or_enum)
 {
   bool constructor_possible_p = !parser->in_declarator_p;
-  cp_decl_spec ds;
 
   /* Clear DECL_SPECS.  */
   clear_decl_specs (decl_specs);
@@ -7559,41 +7602,7 @@ cp_parser_decl_specifier_seq (cp_parser*
       flags |= CP_PARSER_FLAGS_OPTIONAL;
     }
 
-  /* Check for repeated decl-specifiers.  */
-  for (ds = ds_first; ds != ds_last; ++ds)
-    {
-      unsigned count = decl_specs->specs[(int)ds];
-      if (count < 2)
-	continue;
-      /* The "long" specifier is a special case because of "long long".  */
-      if (ds == ds_long)
-	{
-	  if (count > 2)
-	    error ("%<long long long%> is too long for GCC");
-	  else if (pedantic && !in_system_header && warn_long_long)
-	    pedwarn ("ISO C++ does not support %<long long%>");
-	}
-      else if (count > 1)
-	{
-	  static const char *const decl_spec_names[] = {
-	    "signed",
-	    "unsigned",
-	    "short",
-	    "long",
-	    "const",
-	    "volatile",
-	    "restrict",
-	    "inline",
-	    "virtual",
-	    "explicit",
-	    "friend",
-	    "typedef",
-	    "__complex",
-	    "__thread"
-	  };
-	  error ("duplicate %qs", decl_spec_names[(int)ds]);
-	}
-    }
+  cp_parser_check_decl_spec (decl_specs);
 
   /* Don't allow a friend specifier with a class definition.  */
   if (decl_specs->specs[(int) ds_friend] != 0
@@ -12030,6 +12039,8 @@ cp_parser_type_specifier_seq (cp_parser*
       if (is_condition && !is_cv_qualifier)
 	flags |= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES;
     }
+
+  cp_parser_check_decl_spec (type_specifier_seq);
 }
 
 /* Parse a parameter-declaration-clause.
===================================================================

2006-07-14  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28249
	* g++.dg/parse/catch1.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/parse/catch1.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/parse/catch1.C	2006-07-14 16:26:47 +0200
@@ -0,0 +1,8 @@
+// PR c++/28249
+// { dg-do compile }
+
+void foo()
+{
+  try {}
+  catch (long long long) {}  // { dg-error "long long long" }
+}
===================================================================



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