diff mbox series

[C++] Don't require 'bool' in a concept definition.

Message ID 20190314195254.7190-1-jason@redhat.com
State New
Headers show
Series [C++] Don't require 'bool' in a concept definition. | expand

Commit Message

Jason Merrill March 14, 2019, 7:52 p.m. UTC
The concepts overhaul isn't ready yet, but we should at least support concept
definitions without bool; that has been the one thing that prevents people from
writing code that works in both TS and C++20 concepts.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* parser.c (cp_parser_decl_specifier_seq): Support C++20
	concept-definition syntax without 'bool'.
---
 gcc/cp/parser.c                          | 9 +++++++++
 gcc/testsuite/g++.dg/concepts/no-bool1.C | 4 ++++
 gcc/cp/ChangeLog                         | 5 +++++
 3 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/concepts/no-bool1.C


base-commit: a95b8a4616e5112976bf5ba3e63e344fa74c578a
diff mbox series

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 14da1a14501..b8a0245ce57 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13964,6 +13964,15 @@  cp_parser_decl_specifier_seq (cp_parser* parser,
         case RID_CONCEPT:
           ds = ds_concept;
           cp_lexer_consume_token (parser->lexer);
+	  /* In C++20 a concept definition is just 'concept name = expr;'
+	     Support that syntax by pretending we've seen 'bool'.  */
+	  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
+	      && cp_lexer_nth_token_is (parser->lexer, 2, CPP_EQ))
+	    {
+	      cp_parser_set_decl_spec_type (decl_specs, boolean_type_node,
+					    token, /*type_definition*/false);
+	      decl_specs->any_type_specifiers_p = true;
+	    }
           break;
 
 	  /* function-specifier:
diff --git a/gcc/testsuite/g++.dg/concepts/no-bool1.C b/gcc/testsuite/g++.dg/concepts/no-bool1.C
new file mode 100644
index 00000000000..be9b73a0689
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/no-bool1.C
@@ -0,0 +1,4 @@ 
+// { dg-do compile { target c++14 } }
+// { dg-additional-options -fconcepts }
+
+template <class T> concept True = true;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 054a891bcef..6c96c24430f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@ 
+2019-03-14  Jason Merrill  <jason@redhat.com>
+
+	* parser.c (cp_parser_decl_specifier_seq): Support C++20
+	concept-definition syntax without 'bool'.
+
 2019-03-14  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/89512