PR c++/92739 - parsing requires clause with attributes.
authorAndrew Sutton <asutton@lock3software.com>
Tue, 7 Jan 2020 01:02:06 +0000 (01:02 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 7 Jan 2020 01:02:06 +0000 (20:02 -0500)
gcc/cp/
* parser.c (cp_parser_constraint_requires_parens): Exclude
attributes as postfix expressions.

gcc/testsuite/
* g++.dg/concepts-pr92739.C: New test.

From-SVN: r279935

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp2a/concepts-attrib1.C [new file with mode: 0644]

index 3e5f58c..02ebb9f 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-06  Andrew Sutton  <asutton@lock3software.com>
+
+       PR c++/92739 - parsing requires clause with attributes.
+       * parser.c (cp_parser_constraint_requires_parens): Exclude
+       attributes as postfix expressions.
+
 2020-01-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/93138
index 7cd8e15..1ea05dd 100644 (file)
@@ -27256,6 +27256,14 @@ cp_parser_constraint_requires_parens (cp_parser *parser, bool lambda_p)
          gcc_fallthrough ();
        }
       case CPP_OPEN_SQUARE:
+       {
+         /* A primary-constraint-expression followed by a '[[' is not a
+            postfix expression.  */
+         if (cp_lexer_nth_token_is (parser->lexer, 2, CPP_OPEN_SQUARE))
+           return pce_ok;
+
+         gcc_fallthrough ();
+       }
       case CPP_PLUS_PLUS:
       case CPP_MINUS_MINUS:
       case CPP_DOT:
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-attrib1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-attrib1.C
new file mode 100644 (file)
index 0000000..0154afa
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/92739
+// { dg-do compile { target concepts } }
+
+template <class T>
+concept C = true;
+
+template <class T>
+  requires C<T>
+[[nodiscard]] int f(T t) {
+  return 22;
+}
+
+int main() {
+  return 0;
+}