]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Change in DotTemplateExp type semantics leading to regression (PR101619)
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 25 Jul 2021 17:54:08 +0000 (19:54 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Wed, 28 Jul 2021 11:13:04 +0000 (13:13 +0200)
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.

13 files changed:
gcc/d/dmd/MERGE
gcc/d/dmd/expression.c
gcc/d/dmd/expression.h
gcc/testsuite/gdc.test/compilable/test22133.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/fail22133.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/fail7424b.d
gcc/testsuite/gdc.test/fail_compilation/fail7424c.d
gcc/testsuite/gdc.test/fail_compilation/fail7424d.d
gcc/testsuite/gdc.test/fail_compilation/fail7424e.d
gcc/testsuite/gdc.test/fail_compilation/fail7424f.d
gcc/testsuite/gdc.test/fail_compilation/fail7424g.d
gcc/testsuite/gdc.test/fail_compilation/fail7424h.d
gcc/testsuite/gdc.test/fail_compilation/fail7424i.d

index d20785d91262cadb336bfe016bad7cdeed176aaa..127f9f8aa8605794071fbe147588141c1ec54407 100644 (file)
@@ -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.
index 153819aa172082b02179d0eb16ccbac55c7ebcbc..7166f9724241e5328ef86dff82cb9c9404757de4 100644 (file)
@@ -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)
index 2ed8fac373ec6d7017ccdc5706e11d6a701a96be..9413ad9a9312b6d7018d762909533d85fd28f272 100644 (file)
@@ -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 (file)
index 0000000..aff762c
--- /dev/null
@@ -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 (file)
index 0000000..338d96d
--- /dev/null
@@ -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;
+}
index 737958ca6a307ef1afba0e0704fdbd6c66585672..c3fc3116939c67997c5763902277e75770269d42 100644 (file)
@@ -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
index e804d72100bfd0607c23d114e7c16dad4318d8c0..220c995eedd0572ff77a8e77548db4e7e7ec75ef 100644 (file)
@@ -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
index 5ef9463aeb27388edbc755fecf588f0f37c136ca..669c9ff63143aa4a03b06ceb7a2229bfa73cda52 100644 (file)
@@ -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
index ddf4ded953a5030e9cb0372f72b25086651907f4..18bf414ed3af6f33d481faada98c6079b239db41 100644 (file)
@@ -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
index 751b6259d3137e448af1a3f376b1b08b35efa556..29e0ecc9771be9e1c7f66900e63949e6525bf489 100644 (file)
@@ -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
index d4fa4635d8d2c8e02a5ce5f0905e40b6e9529eaf..b4670de362410ba9014d2e71dda036ff68092162 100644 (file)
@@ -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
index 56184a5f5a12649910a0f14742eeb99c68ed3467..b76f5b352e18e8d5d2c7cb261784ef8e803004ae 100644 (file)
@@ -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
index 37042f741f368ffe036b1cc97bca6bb07e2ed302..887c85970b83f8c6d4ed069ce7c0884287d91d6c 100644 (file)
@@ -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