From patchwork Tue Jan 5 13:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1422444 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=bNudVXNr; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D9Cph4Q7zz9s1l for ; Wed, 6 Jan 2021 00:22:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7D573854830; Tue, 5 Jan 2021 13:22:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id 092583857C63 for ; Tue, 5 Jan 2021 13:22:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 092583857C63 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf30.google.com with SMTP id p12so14588747qvj.13 for ; Tue, 05 Jan 2021 05:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=1Sz2ftSDL98Xj4Z+mltC6XmN/Vmht29SNMXmmv0l7OA=; b=bNudVXNrRHKtOK/74RgFIfmcmTmltQOdwdpJzLwaDbb65rBwzcU70aGYNyjE59XPgW UAjRuCpMVlRkSTJHpzuW449Kgav8eLkcMwOdjsn29cGQtySc5A3AeXanHOC/qK0gPYdw dY5erDXPVbBZEWtG5/+HHunjSwyLBGmIlfyke0fRGA5USdoeKuY7ovJpNcM9K+WLkhvO QeJm/5G4cXxMYGfkZcIpT+5BhOAKsCM9KbXfiu9Elh2F8p0Auqr7UAWx2MIco48/DV8C IO0QGaqx7yeFiwb9Kuma7rk6Yt5o1s8uAOLxCOc4vhLSXZY0KDdSoEKDUZ2CbjecusRH fHEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=1Sz2ftSDL98Xj4Z+mltC6XmN/Vmht29SNMXmmv0l7OA=; b=RV1PqgT1TXo1xLTQX9TAmdwZPaYUe6EKhOQXBZtAOxrynkfv/OCkbMY9s500CjOYRF haTES5H6uhtmROgHlceKSIbL4eovOuIaYvHf3OTc64yqnas62mS6MFMFfkqkSfqD3SxS AvNiRTZVazEahf0CHaY69uEt4mGnubsiJF05tUTBAVIdxNDJ9tihuDgR/Tdlh+BsGKQK 9a/44SNKNONkSl0WUb8XJSciq/9ukixy7Tly3pKBP2F/v3eRuL8vtsN6naVwxaGXnZxE XWjABC5aQCkRYyw5z5lSqlSqwA/GgNNDnmhn+jF29js849vC4huWCkKU2Z3TV0BEI5/C E8Aw== X-Gm-Message-State: AOAM532smZSrx+P3jTdlPDIuHLh2l5gUCLreFnM4TZVDzCgjpKt1doNc mMoXUKgiSDX1oJ5zN21piek= X-Google-Smtp-Source: ABdhPJxXQ2PVATJzueiVFXhiLfFP9gLkhyyorXh7PCaAR+jT7H+u8m5NKaC2AjvmYEjdTGqV6klfjw== X-Received: by 2002:a0c:8e4b:: with SMTP id w11mr50647312qvb.30.1609852945407; Tue, 05 Jan 2021 05:22:25 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:90b:374:4e4c:c5c2? ([2620:10d:c091:480::1:7075]) by smtp.googlemail.com with ESMTPSA id q20sm39239231qkj.49.2021.01.05.05.22.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Jan 2021 05:22:24 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [c++]: Improve module-decl diagnostics [PR 98327] Message-ID: <7b3830ac-e52f-aa56-4aac-6bcf22e20406@acm.org> Date: Tue, 5 Jan 2021 08:22:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The diagnostic for a misplaced module decl was essentially 'computer says no', which isn't the most helpful. This adjusts it to indicate what would be acceptable. gcc/cp/ * parser.cc (cp_parser_module_declaration): Alter diagnostic text to say where is permissable. gcc/testsuite/ * g++.dg/modulex/mod-decl-1.C: Adjust. * g++.dg/modulex/p0713-2.C: Adjust. * g++.dg/modulex/p0713-3.C: Adjust. diff --git i/gcc/cp/parser.c w/gcc/cp/parser.c index d855e034458..c713852fe93 100644 --- i/gcc/cp/parser.c +++ w/gcc/cp/parser.c @@ -13726,19 +13726,22 @@ cp_parser_module_declaration (cp_parser *parser, module_parse mp_state, cp_lexer_consume_token (parser->lexer); cp_parser_require_pragma_eol (parser, token); - if ((mp_state != MP_PURVIEW && mp_state != MP_PURVIEW_IMPORTS) + if (!(mp_state == MP_PURVIEW || mp_state == MP_PURVIEW_IMPORTS) || !module_interface_p () || module_partition_p ()) error_at (token->location, - "private module fragment not permitted here"); + "private module fragment only permitted in purview" + " of module interface or partition"); else { mp_state = MP_PRIVATE_IMPORTS; sorry_at (token->location, "private module fragment"); } } - else if (mp_state != MP_FIRST && mp_state != MP_GLOBAL) + else if (!(mp_state == MP_FIRST || mp_state == MP_GLOBAL)) { - error_at (token->location, "module-declaration not permitted here"); + /* Neither the first declaration, nor in a GMF. */ + error_at (token->location, "module-declaration only permitted as first" + " declaration, or ending a global module fragment"); skip_eol: cp_parser_skip_to_pragma_eol (parser, token); } diff --git i/gcc/testsuite/g++.dg/modules/mod-decl-1.C w/gcc/testsuite/g++.dg/modules/mod-decl-1.C index b2665bec743..23d34483dd7 100644 --- i/gcc/testsuite/g++.dg/modules/mod-decl-1.C +++ w/gcc/testsuite/g++.dg/modules/mod-decl-1.C @@ -6,11 +6,11 @@ export module frist; import frist; // { dg-error {cannot import module.* in its own purview} } -module foo.second; // { dg-error "not permitted here" } +module foo.second; // { dg-error "only permitted as" } namespace Foo { -module third; // { dg-error "not permitted here" } +module third; // { dg-error "only permitted as" } } struct Baz @@ -23,7 +23,7 @@ void Bink () module fifth; // { dg-error "expected" } } -module a.; // { dg-error "not permitted" } +module a.; // { dg-error "only permitted as" } // { dg-prune-output "not writing module" } diff --git i/gcc/testsuite/g++.dg/modules/p0713-2.C w/gcc/testsuite/g++.dg/modules/p0713-2.C index c7846e450a9..cb4ccb6c5f6 100644 --- i/gcc/testsuite/g++.dg/modules/p0713-2.C +++ w/gcc/testsuite/g++.dg/modules/p0713-2.C @@ -1,3 +1,3 @@ // { dg-additional-options "-fmodules-ts" } int j; -module; // { dg-error "not permitted" } +module; // { dg-error "only permitted as" } diff --git i/gcc/testsuite/g++.dg/modules/p0713-3.C w/gcc/testsuite/g++.dg/modules/p0713-3.C index 3c539ebab3e..09d89b73b3f 100644 --- i/gcc/testsuite/g++.dg/modules/p0713-3.C +++ w/gcc/testsuite/g++.dg/modules/p0713-3.C @@ -1,6 +1,6 @@ // { dg-additional-options "-fmodules-ts" } int k; -module frob; // { dg-error "not permitted" } +module frob; // { dg-error "only permitted as" } // { dg-prune-output "failed to read" } // { dg-prune-output "fatal error:" } // { dg-prune-output "compilation terminated" }