c++: add "'requires' only available with ..." note
authorPatrick Palka <ppalka@redhat.com>
Sat, 25 Apr 2020 01:16:59 +0000 (21:16 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 25 Apr 2020 01:16:59 +0000 (21:16 -0400)
This adds a note suggesting to enable concepts whenever 'requires' is parsed as
an invalid type name with concepts disabled.

gcc/cp/ChangeLog:

* parser.c (cp_parser_diagnose_invalid_type_name): Suggest enabling
concepts if the invalid identifier is 'requires'.

gcc/testsuite/ChangeLog:

* g++.dg/concepts/diagnostic11.C: New test.

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

index 5b9ff5a694cde14679a13ee735341fe1e934304b..2a5b417136685b5cea1bfae4a556a07ac6323383 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-25  Patrick Palka  <ppalka@redhat.com>
+
+       * parser.c (cp_parser_diagnose_invalid_type_name): Suggest enabling
+       concepts if the invalid identifier is 'requires'.
+
 2020-04-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/94742
index d2f3f853cb410166cac262fea0ea3f99aced853d..e1f9786893acd460c0e0e6adf1423dfc3b1d0e50 100644 (file)
@@ -3378,6 +3378,9 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
       else if (!flag_concepts && id == ridpointers[(int)RID_CONCEPT])
        inform (location, "%<concept%> only available with %<-std=c++2a%> or "
                "%<-fconcepts%>");
+      else if (!flag_concepts && id == ridpointers[(int)RID_REQUIRES])
+       inform (location, "%<requires%> only available with %<-std=c++2a%> or "
+               "%<-fconcepts%>");
       else if (processing_template_decl && current_class_type
               && TYPE_BINFO (current_class_type))
        {
index b9be66865cda9ff54f9667a6bb35a7cbf0c16296..efbfe99d0d9ad4dce389ec63b19ecada0048bda9 100644 (file)
@@ -1,3 +1,7 @@
+2020-04-25  Patrick Palka  <ppalka@redhat.com>
+
+       * g++.dg/concepts/diagnostic11.C: New test.
+
 2020-04-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/94742
diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic11.C b/gcc/testsuite/g++.dg/concepts/diagnostic11.C
new file mode 100644 (file)
index 0000000..7c60912
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++17_only } }
+
+template <bool B>
+  requires B // { dg-error ".requires. does not name a type" }
+// { dg-message ".requires. only available with" "" { target *-*-* } .-1 }
+void foo() { }