This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR c++/36475 [gomp] register keyword in openmp handled for-loop fails
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "Gcc Patch List" <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 26 Oct 2008 13:31:02 +0100
- Subject: PR c++/36475 [gomp] register keyword in openmp handled for-loop fails
If you can imagine testcases where this approach may produce worse
results than the current code, please let me know. Notice that the new
cases should only affect invalid code. For valid code I think the
results should be the same as jumping directly to default.
Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,obj-c++ --enable-decimal-float.
OK for trunk?
2008-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c++/pr36475
cp/
* parser.c (cp_parser_primary_expression): If we found something
that is not allowed at this point, just say so.
testsuite/
* g++.dg/gomp/pr36475.C: New.
Index: gcc/testsuite/g++.dg/gomp/pr36475.C
===================================================================
--- gcc/testsuite/g++.dg/gomp/pr36475.C (revision 0)
+++ gcc/testsuite/g++.dg/gomp/pr36475.C (revision 0)
@@ -0,0 +1,9 @@
+// PR c++/36475
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+int main() {
+#pragma omp parallel for
+ for (register int i = 0; i < 2; ++i) { // { dg-error ".register. is not allowed" }
+ }
+ return 0;
+}
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 141361)
+++ gcc/cp/parser.c (working copy)
@@ -3372,10 +3372,21 @@ cp_parser_primary_expression (cp_parser
case RID_AT_ENCODE:
case RID_AT_PROTOCOL:
case RID_AT_SELECTOR:
return cp_parser_objc_expression (parser);
+ case RID_REGISTER:
+ case RID_STATIC:
+ case RID_EXTERN:
+ case RID_MUTABLE:
+ if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
+ error ("%H%qE is not allowed here",
+ &token->location, token->u.value);
+ cp_parser_simulate_error (parser);
+ cp_lexer_consume_token (parser->lexer);
+ return error_mark_node;
+
default:
cp_parser_error (parser, "expected primary-expression");
return error_mark_node;
}
@@ -10873,10 +10884,12 @@ cp_parser_type_specifier (cp_parser* par
if (declares_class_or_enum)
*declares_class_or_enum = 0;
/* And that it does not specify a cv-qualifier. */
if (is_cv_qualifier)
*is_cv_qualifier = false;
+
+ restart:
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
/* If we're looking at a keyword, we can use that to guide the
production we choose. */
@@ -10966,10 +10979,19 @@ cp_parser_type_specifier (cp_parser* par
case RID_COMPLEX:
/* The `__complex__' keyword is a GNU extension. */
ds = ds_complex;
break;
+ case RID_REGISTER:
+ case RID_STATIC:
+ case RID_EXTERN:
+ case RID_MUTABLE:
+ error ("%H%qE is not allowed here",
+ &token->location, token->u.value);
+ cp_lexer_consume_token (parser->lexer);
+ goto restart;
+
default:
break;
}
/* Handle simple keywords. */