This adds a note suggesting to enable concepts whenever 'requires' is parsed as
an invalid type name with concepts disabled.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit?

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

        * g++.dg/concepts/diagnostic11.C: New test.
---
 gcc/cp/parser.c                              | 3 +++
 gcc/testsuite/g++.dg/concepts/diagnostic11.C | 6 ++++++
 2 files changed, 9 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/concepts/diagnostic11.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 47e3f2bbd3d..337f22d2784 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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))
        {
diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic11.C 
b/gcc/testsuite/g++.dg/concepts/diagnostic11.C
new file mode 100644
index 00000000000..7c60912352a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/diagnostic11.C
@@ -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() { }
-- 
2.26.2.266.ge870325ee8

Reply via email to