From patchwork Mon Feb 10 16:28:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1235883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519247-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.a=rsa-sha1 header.s=default header.b=CXdcwVT4; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AqP7bCfZ; 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 48GWYL2cHRz9sP7 for ; Tue, 11 Feb 2020 03:28:20 +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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Gl61yev1DusMYFeV HZHCInIhByMFhsWGPFzthIMYPKhC1Z1dU5cb02YAAhTNC01SRmiV5rZHYBIKEIza 4mp04lJeZ+g7l7owUIUui7rCuAG031eWRRGnGqz67kOQMpoOWiWB2A6JtKvpXwYF gmfXR8nSbAzBjyhBrlrjWaSGC8M= 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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=um17DNd23hzvucTneL/XLm f7T/E=; b=CXdcwVT4waotE/mV9MMsO16a6kegt4dxT9l8w/BgaAh0zOYSMIN5C9 d3BdsJSHAcITCo0G2Uvlz3HdmSO+RV6bkDzqkKDb3GYARQmhAS9GV3rF4Hykyk0W NKxyfRZJzi0ei6BP7+tujb2McWxxYGxTeMjgLBPm9Vu4V6JGcx9JI= Received: (qmail 94294 invoked by alias); 10 Feb 2020 16:28:13 -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 94286 invoked by uid 89); 10 Feb 2020 16:28:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 16:28:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581352090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Sa9euFTznfyAbHXKoYmzKu7NmLxAFE53mf0Eab00v5U=; b=AqP7bCfZgJKTBatkbxAZJsZ7T37xLWYy8guj9XzXFNKj7TAlMdygeR5BqKWru6Ea5ytOZm 0/4ac+IVDIR7wkF1PwsSTVS5yN0hgNbYu187MwqCFS94rkaP11DexgWGk+1J1WDyhLYPRm LNPs+RaYn27zvEtcp4LwLW0RqCjikrk= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-CT6fTixsPSq89txIUod3PQ-1; Mon, 10 Feb 2020 11:28:05 -0500 Received: by mail-qt1-f200.google.com with SMTP id c10so4737600qtk.18 for ; Mon, 10 Feb 2020 08:28:05 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id z5sm437013qta.7.2020.02.10.08.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 08:28:04 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: Improve dump_decl for standard concepts Date: Mon, 10 Feb 2020 11:28:01 -0500 Message-Id: <20200210162801.775454-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This patch improves the pretty printing of standard concept definitions in error messages. In particular, standard concepts are now printed qualified whenever appropriate, and the "concept" specifier is printed only when the TFF_DECL_SPECIFIERS flag is specified. In the below test, the first error message changes from 9:15: error: ‘b’ was not declared in this scope; did you mean ‘concept b’? to 9:15: error: ‘b’ was not declared in this scope; did you mean ‘a::b’? Tested on x86_64-pc-linux-gnu, is this OK to commit? gcc/cp/ChangeLog: * error.c (dump_decl) [CONCEPT_DECL]: Use dump_simple_decl. (dump_simple_decl): Handle standard concept definitions as well as variable concept definitions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts6.C: New test. --- gcc/cp/error.c | 18 ++++++++---------- gcc/testsuite/g++.dg/cpp2a/concepts6.C | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts6.C diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 973b3034e12..a56d83e1f45 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1037,14 +1037,13 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) if (flags & TFF_DECL_SPECIFIERS) { - if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t)) - { - if (DECL_LANG_SPECIFIC (t) && DECL_DECLARED_CONCEPT_P (t)) - pp_cxx_ws_string (pp, "concept"); - else - pp_cxx_ws_string (pp, "constexpr"); - } - dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME); + if (concept_definition_p (t)) + pp_cxx_ws_string (pp, "concept"); + else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t)) + pp_cxx_ws_string (pp, "constexpr"); + + if (!standard_concept_p (t)) + dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME); pp_maybe_space (pp); } if (! (flags & TFF_UNQUALIFIED_NAME) @@ -1296,8 +1295,7 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags) break; case CONCEPT_DECL: - pp_cxx_ws_string (pp, "concept"); - dump_decl_name (pp, DECL_NAME (t), flags); + dump_simple_decl (pp, t, TREE_TYPE (t), flags); break; case WILDCARD_DECL: diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts6.C b/gcc/testsuite/g++.dg/cpp2a/concepts6.C new file mode 100644 index 00000000000..d69628b0318 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts6.C @@ -0,0 +1,18 @@ +// { dg-do compile { target c++2a } } + +namespace a +{ + template + concept b = true; // { dg-message ".a::b. declared here" } +} + +static_assert(b); // { dg-error "did you mean .a::b." } + +namespace c +{ + template + concept b = true; // { dg-message "concept c::b." } + + template + concept b = true; // { dg-error "concept c::b." } +}