From patchwork Thu Mar 14 19:52:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1056687 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497923-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SkNTIFi+"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44KzsH5dqYz9s00 for ; Fri, 15 Mar 2019 06:53:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=PfzhIeh0p8SUaCG3 TornX6Q5VC4SZ1lsoi9lB75ebezv0wouc2vBtLHRL/mtAxBfL3uDlDQWvEDf5q17 d5D84LLgAm2hinuaKcWy0pWydCjeP58kOBsYKp+JJkF2fHWRfDhfgg7S8nLEughm 1w1lC/U80WKAz2TfhBcqKSw54h8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=Ff0lyT9iRwQPtgsNo7WVtZ GfsE0=; b=SkNTIFi+6Ed8HRsRG7IjuiyHUJTtALC6miufvqft+K2AQHtlS0O/ry 9cvdFx7hFveaSAkcgQ7Zo9IwHbEjtFusuqXc1nXHj+DD2FQFNiFIw7kBPGlThzpr JMcqcJGsMFQj88qv8TNArNjUbISSGOGxr4cFsXlvIMSr2M8o/Oygg= Received: (qmail 82262 invoked by alias); 14 Mar 2019 19:53:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82239 invoked by uid 89); 14 Mar 2019 19:53:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail-qt1-f172.google.com Received: from mail-qt1-f172.google.com (HELO mail-qt1-f172.google.com) (209.85.160.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Mar 2019 19:52:59 +0000 Received: by mail-qt1-f172.google.com with SMTP id v32so7528147qtc.10 for ; Thu, 14 Mar 2019 12:52:58 -0700 (PDT) Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id j9sm9008109qki.21.2019.03.14.12.52.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 12:52:56 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Don't require 'bool' in a concept definition. Date: Thu, 14 Mar 2019 15:52:54 -0400 Message-Id: <20190314195254.7190-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes 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 --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 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 + + * parser.c (cp_parser_decl_specifier_seq): Support C++20 + concept-definition syntax without 'bool'. + 2019-03-14 Jakub Jelinek PR c++/89512