diff mbox series

c++: add "'requires' only available with ..." note

Message ID 20200424195221.3604674-1-ppalka@redhat.com
State New
Headers show
Series c++: add "'requires' only available with ..." note | expand

Commit Message

Patrick Palka April 24, 2020, 7:52 p.m. UTC
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

Comments

Jason Merrill April 24, 2020, 8:07 p.m. UTC | #1
On 4/24/20 3:52 PM, Patrick Palka wrote:
> 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?

OK.

> 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() { }
>
diff mbox series

Patch

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() { }