]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/71909 (g++ accepts an unreachable function catch block that lacks a corresp...
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Jul 2016 14:32:46 +0000 (16:32 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 20 Jul 2016 14:32:46 +0000 (16:32 +0200)
PR c++/71909
* parser.c (cp_parser_save_member_function_body): Consume
__transaction_relaxed or __transaction_atomic with optional
attribute.  Only skip catch with block if try keyword is seen.

* g++.dg/parse/pr71909.C: New test.
* g++.dg/tm/pr71909.C: New test.

From-SVN: r238527

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/pr71909.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tm/pr71909.C [new file with mode: 0644]

index dd8c0005dba1515e53ffb1ef52c89ea3d1f5b689..5936ea64590b2c422c2c9efd6ab4babb7f0bead7 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71909
+       * parser.c (cp_parser_save_member_function_body): Consume
+       __transaction_relaxed or __transaction_atomic with optional
+       attribute.  Only skip catch with block if try keyword is seen.
+
 2016-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 50ce667ad48e7b46357165ebda34a42ddd57fe12..e06bb0a1b4bc2ae4e20f1e6025c3f31100afc06a 100644 (file)
@@ -23366,6 +23366,7 @@ cp_parser_save_member_function_body (cp_parser* parser,
   cp_token *first;
   cp_token *last;
   tree fn;
+  bool function_try_block = false;
 
   /* Create the FUNCTION_DECL.  */
   fn = grokmethod (decl_specifiers, declarator, attributes);
@@ -23386,9 +23387,48 @@ cp_parser_save_member_function_body (cp_parser* parser,
   /* Save away the tokens that make up the body of the
      function.  */
   first = parser->lexer->next_token;
+
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRANSACTION_RELAXED))
+    cp_lexer_consume_token (parser->lexer);
+  else if (cp_lexer_next_token_is_keyword (parser->lexer,
+                                          RID_TRANSACTION_ATOMIC))
+    {
+      cp_lexer_consume_token (parser->lexer);
+      /* Match cp_parser_txn_attribute_opt [[ identifier ]].  */
+      if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE)
+         && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
+             == CPP_OPEN_SQUARE)
+         && (cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_NAME
+             || (cp_lexer_peek_nth_token (parser->lexer, 3)->type
+                 == CPP_KEYWORD))
+         && (cp_lexer_peek_nth_token (parser->lexer, 4)->type
+             == CPP_CLOSE_SQUARE)
+         && (cp_lexer_peek_nth_token (parser->lexer, 5)->type
+             == CPP_CLOSE_SQUARE))
+       {
+         cp_lexer_consume_token (parser->lexer);
+         cp_lexer_consume_token (parser->lexer);
+         cp_lexer_consume_token (parser->lexer);
+         cp_lexer_consume_token (parser->lexer);
+         cp_lexer_consume_token (parser->lexer);
+       }
+      else
+       while (cp_next_tokens_can_be_gnu_attribute_p (parser)
+              && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
+                  == CPP_OPEN_PAREN))
+         {
+           cp_lexer_consume_token (parser->lexer);
+           if (cp_parser_cache_group (parser, CPP_CLOSE_PAREN, /*depth=*/0))
+             break;
+         }
+    }
+
   /* Handle function try blocks.  */
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
-    cp_lexer_consume_token (parser->lexer);
+    {
+      cp_lexer_consume_token (parser->lexer);
+      function_try_block = true;
+    }
   /* We can have braced-init-list mem-initializers before the fn body.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
     {
@@ -23406,8 +23446,9 @@ cp_parser_save_member_function_body (cp_parser* parser,
     }
   cp_parser_cache_group (parser, CPP_CLOSE_BRACE, /*depth=*/0);
   /* Handle function try blocks.  */
-  while (cp_lexer_next_token_is_keyword (parser->lexer, RID_CATCH))
-    cp_parser_cache_group (parser, CPP_CLOSE_BRACE, /*depth=*/0);
+  if (function_try_block)
+    while (cp_lexer_next_token_is_keyword (parser->lexer, RID_CATCH))
+      cp_parser_cache_group (parser, CPP_CLOSE_BRACE, /*depth=*/0);
   last = parser->lexer->next_token;
 
   /* Save away the inline definition; we will process it when the
index 78e80bec32ca98c93019e3af0d2bdd1e4cd753d9..c61873a29fd119b376c789c46a43ea0a16a0132d 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71909
+       * g++.dg/parse/pr71909.C: New test.
+       * g++.dg/tm/pr71909.C: New test.
+
 2016-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/71874
diff --git a/gcc/testsuite/g++.dg/parse/pr71909.C b/gcc/testsuite/g++.dg/parse/pr71909.C
new file mode 100644 (file)
index 0000000..ee592bf
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/71909
+// { dg-do compile }
+
+struct S
+{
+  S () try : m (0) {}
+  catch (...) {}
+  void foo () try {}
+  catch (int) {}
+  catch (...) {}
+  int m;
+};
+
+struct T
+{
+  T () : m (0) {}
+  catch (...) {}       // { dg-error "expected unqualified-id before" }
+  void foo () {}
+  catch (int) {}       // { dg-error "expected unqualified-id before" }
+  catch (...) {}       // { dg-error "expected unqualified-id before" }
+  int m;
+};
diff --git a/gcc/testsuite/g++.dg/tm/pr71909.C b/gcc/testsuite/g++.dg/tm/pr71909.C
new file mode 100644 (file)
index 0000000..941f231
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/71909
+// { dg-do compile { target c++11 } }
+// { dg-options "-fgnu-tm" }
+
+struct S
+{
+  S () __transaction_atomic [[outer]] try : m {0} {} catch (int) {} catch (...) {}
+  int m;
+};
+
+struct T
+{
+  T () __transaction_atomic __attribute__((outer)) try : m {0} {} catch (int) {} catch (...) {}
+  int m;
+};
+
+void foo () __transaction_atomic [[outer]] try {} catch (int) {} catch (...) {}
+void bar () __transaction_atomic __attribute__((outer)) try {} catch (int) {} catch (...) {}