diff mbox series

[committed] d: Change in DotTemplateExp type semantics leading to regression (PR101619)

Message ID 20210728112326.3740022-1-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] d: Change in DotTemplateExp type semantics leading to regression (PR101619) | expand

Commit Message

Iain Buclaw July 28, 2021, 11:23 a.m. UTC
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 mbox series

Patch

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