Hi! If omp::directive attribute argument starting with the opening ( is not a balanced token sequence, then cp_parser_skip_balanced_tokens (parser, 1) returns 1, but the code was subtracting 2 from it and iterating until it was 0, so for the non-balanced case it iterated from (size_t) -1 down to 0.
The following patch just diagnoses that as an error. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2021-09-23 Jakub Jelinek <ja...@redhat.com> PR c++/102413 * parser.c (cp_parser_omp_directive_args): Diagnose if omp::directive is not followed by a balanced token sequence starting with open paren. * g++.dg/gomp/attrs-14.C: New test. --- gcc/cp/parser.c.jj 2021-09-22 09:29:01.060813877 +0200 +++ gcc/cp/parser.c 2021-09-22 14:24:56.820568683 +0200 @@ -28628,7 +28628,16 @@ cp_parser_omp_directive_args (cp_parser TREE_VALUE (attribute) = NULL_TREE; return; } - for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 2; n; --n) + size_t n = cp_parser_skip_balanced_tokens (parser, 1); + if (n == 1) + { + cp_lexer_consume_token (parser->lexer); + error_at (first->location, "expected attribute argument as balanced " + "token sequence"); + TREE_VALUE (attribute) = NULL_TREE; + return; + } + for (n = n - 2; n; --n) cp_lexer_consume_token (parser->lexer); cp_token *last = cp_lexer_peek_token (parser->lexer); cp_lexer_consume_token (parser->lexer); --- gcc/testsuite/g++.dg/gomp/attrs-14.C.jj 2021-09-22 14:27:08.614689785 +0200 +++ gcc/testsuite/g++.dg/gomp/attrs-14.C 2021-09-22 14:28:12.681776426 +0200 @@ -0,0 +1,4 @@ +// PR c++/102413 +// { dg-do compile { target c++11 } } + +[[omp::directive(error]]; // { dg-error "expected|declare" } Jakub