From patchwork Wed Jul 28 11:23:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1510805 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RW1TlhzP; 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 4GZWXT1LcTz9sRN for ; Wed, 28 Jul 2021 21:24:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 981413990C30 for ; Wed, 28 Jul 2021 11:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 981413990C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627471477; bh=lAOy1xx9a9e6T5Lcf+graOJxQ2++E6PxnJpfDR7XVmQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RW1TlhzPtoct9zmFQG3aASZbK9g7Lr3bqqoZZh7PXDxFzaXZ4yIU89QS200A2RcI6 q+4bcWw2sNYULUVYJ0SiFjF+BtR7xS+StBFrkA1CGEWb5M2t9jaiay9WqZfNF6IM/W WqizMQa5JHBoYlLFoi59390fCczQEGEd8l/HTAlQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050::465:201]) by sourceware.org (Postfix) with ESMTPS id 98DE3399202A for ; Wed, 28 Jul 2021 11:23:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98DE3399202A Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4GZWW92LlszQjh9; Wed, 28 Jul 2021 13:23:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id Vz3SZNCZqLAv; Wed, 28 Jul 2021 13:23:29 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Change in DotTemplateExp type semantics leading to regression (PR101619) Date: Wed, 28 Jul 2021 13:23:26 +0200 Message-Id: <20210728112326.3740022-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1BD2E18BF X-Rspamd-UID: c67ef6 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes a regression introduced by PR100999. By giving dot templates a type, meant that properry resolving silently started passing for code that should never have passed. The simple fix is to provide implementations for checkType and checkValue that give an error about dot templates having neither a value nor type. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32. Committed to mainline, and backported to the gcc-10 and gcc-11 release branches. Regards, Iain. --- gcc/d/ChangeLog: PR d/101619 * dmd/MERGE: Merge upstream dmd 1d8386a63. --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/expression.c | 12 ++++++++++ gcc/d/dmd/expression.h | 2 ++ gcc/testsuite/gdc.test/compilable/test22133.d | 16 +++++++++++++ .../gdc.test/fail_compilation/fail22133.d | 24 +++++++++++++++++++ .../gdc.test/fail_compilation/fail7424b.d | 2 +- .../gdc.test/fail_compilation/fail7424c.d | 2 +- .../gdc.test/fail_compilation/fail7424d.d | 2 +- .../gdc.test/fail_compilation/fail7424e.d | 2 +- .../gdc.test/fail_compilation/fail7424f.d | 2 +- .../gdc.test/fail_compilation/fail7424g.d | 2 +- .../gdc.test/fail_compilation/fail7424h.d | 2 +- .../gdc.test/fail_compilation/fail7424i.d | 2 +- 13 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gdc.test/compilable/test22133.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail22133.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index d20785d9126..127f9f8aa86 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -7a3808254878df8cb70a055bea58afc79187b778 +1d8386a63d412c9e77728b0b965025ac4dd40b75 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/expression.c b/gcc/d/dmd/expression.c index 153819aa172..7166f972424 100644 --- a/gcc/d/dmd/expression.c +++ b/gcc/d/dmd/expression.c @@ -4200,6 +4200,18 @@ DotTemplateExp::DotTemplateExp(Loc loc, Expression *e, TemplateDeclaration *td) this->td = td; } +bool DotTemplateExp::checkType() +{ + error("%s %s has no type", td->kind(), toChars()); + return true; +} + +bool DotTemplateExp::checkValue() +{ + error("%s %s has no value", td->kind(), toChars()); + return true; +} + /************************************************************/ DotVarExp::DotVarExp(Loc loc, Expression *e, Declaration *var, bool hasOverloads) diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h index 2ed8fac373e..9413ad9a931 100644 --- a/gcc/d/dmd/expression.h +++ b/gcc/d/dmd/expression.h @@ -930,6 +930,8 @@ public: TemplateDeclaration *td; DotTemplateExp(Loc loc, Expression *e, TemplateDeclaration *td); + bool checkType(); + bool checkValue(); void accept(Visitor *v) { v->visit(this); } }; diff --git a/gcc/testsuite/gdc.test/compilable/test22133.d b/gcc/testsuite/gdc.test/compilable/test22133.d new file mode 100644 index 00000000000..aff762c7180 --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/test22133.d @@ -0,0 +1,16 @@ +// https://issues.dlang.org/show_bug.cgi?id=22133 + +struct Slice +{ + bool empty() const; + int front() const; + void popFront()() // note: requires a mutable Slice + {} +} + +enum isInputRange1(R) = is(typeof((R r) => r.popFront)); +enum isInputRange2(R) = __traits(compiles, (R r) => r.popFront); +static assert(isInputRange1!( Slice) == true); +static assert(isInputRange1!(const Slice) == false); +static assert(isInputRange2!( Slice) == true); +static assert(isInputRange2!(const Slice) == false); diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail22133.d b/gcc/testsuite/gdc.test/fail_compilation/fail22133.d new file mode 100644 index 00000000000..338d96dc7e1 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail22133.d @@ -0,0 +1,24 @@ +// https://issues.dlang.org/show_bug.cgi?id=22133 +/* +TEST_OUTPUT +--- +fail_compilation/fail22133.d(16): Error: `s.popFront()()` has no effect +fail_compilation/fail22133.d(17): Error: template `s.popFront()()` has no type +--- +*/ +struct Slice +{ + void popFront()() {} +} + +auto fail22133(const Slice s) +{ + s.popFront; + return s.popFront; +} + +auto ok22133(Slice s) +{ + s.popFront; + return s.popFront; +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424b.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424b.d index 737958ca6a3..c3fc3116939 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424b.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424b.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424b.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424b.d(10): Error: template `this.g()()` has no value --- */ struct S7424b diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424c.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424c.d index e804d72100b..220c995eedd 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424c.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424c.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424c.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424c.d(10): Error: template `this.g()()` has no value --- */ struct S7424c diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424d.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424d.d index 5ef9463aeb2..669c9ff6314 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424d.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424d.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424d.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424d.d(10): Error: template `this.g()()` has no value --- */ struct S7424d diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424e.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424e.d index ddf4ded953a..18bf414ed3a 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424e.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424e.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424e.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424e.d(10): Error: template `this.g()()` has no value --- */ struct S7424e diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424f.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424f.d index 751b6259d31..29e0ecc9771 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424f.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424f.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424f.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424f.d(10): Error: template `this.g()()` has no value --- */ struct S7424f diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424g.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424g.d index d4fa4635d8d..b4670de3624 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424g.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424g.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424g.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424g.d(10): Error: template `this.g()()` has no value --- */ struct S7424g diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424h.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424h.d index 56184a5f5a1..b76f5b352e1 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424h.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424h.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424h.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424h.d(10): Error: template `this.g()()` has no value --- */ struct S7424g diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7424i.d b/gcc/testsuite/gdc.test/fail_compilation/fail7424i.d index 37042f741f3..887c85970b8 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail7424i.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail7424i.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7424i.d(10): Error: expression `this.g()()` is `void` and has no value +fail_compilation/fail7424i.d(10): Error: template `this.g()()` has no value --- */ struct S7424g