From: Iain Buclaw Date: Sun, 25 Jul 2021 17:54:08 +0000 (+0200) Subject: d: Change in DotTemplateExp type semantics leading to regression (PR101619) X-Git-Tag: basepoints/gcc-13~5752 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e2136117487fa839f7601c3e22a2856978fb9d0;p=thirdparty%2Fgcc.git d: Change in DotTemplateExp type semantics leading to regression (PR101619) 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. Reviewed-on: https://github.com/dlang/dmd/pull/12920 PR d/101619 gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 1d8386a63. --- diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index d20785d91262..127f9f8aa860 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 153819aa1720..7166f9724241 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 2ed8fac373ec..9413ad9a9312 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 000000000000..aff762c71806 --- /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 000000000000..338d96dc7e11 --- /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 737958ca6a30..c3fc3116939c 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 e804d72100bf..220c995eedd0 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 5ef9463aeb27..669c9ff63143 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 ddf4ded953a5..18bf414ed3af 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 751b6259d313..29e0ecc9771b 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 d4fa4635d8d2..b4670de36241 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 56184a5f5a12..b76f5b352e18 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 37042f741f36..887c85970b83 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