public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10004] d: Change in DotTemplateExp type semantics leading to regression (PR101619)
@ 2021-07-28 11:50 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-28 11:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:54e7981234503e354602088c60cb5b27c8a015d6

commit r10-10004-g54e7981234503e354602088c60cb5b27c8a015d6
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sun Jul 25 19:54:08 2021 +0200

    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/expression.c (DotTemplateExp::checkType): New function.
            (DotTemplateExp::checkValue): New function.
            * dmd/expression.h (class DotTemplateExp): Declare checkType and
            checkValue.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.test/fail_compilation/fail7424b.d: Update test.
            * gdc.test/fail_compilation/fail7424c.d: Update test.
            * gdc.test/fail_compilation/fail7424d.d: Update test.
            * gdc.test/fail_compilation/fail7424e.d: Update test.
            * gdc.test/fail_compilation/fail7424f.d: Update test.
            * gdc.test/fail_compilation/fail7424g.d: Update test.
            * gdc.test/fail_compilation/fail7424h.d: Update test.
            * gdc.test/fail_compilation/fail7424i.d: Update test.
            * gdc.test/compilable/test22133.d: New test.
            * gdc.test/fail_compilation/fail22133.d: New test.
    
    (cherry picked from commit 3e2136117487fa839f7601c3e22a2856978fb9d0)

Diff:
---
 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 +-
 12 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/gcc/d/dmd/expression.c b/gcc/d/dmd/expression.c
index 6d28e24e35c..5b70ce5ca60 100644
--- a/gcc/d/dmd/expression.c
+++ b/gcc/d/dmd/expression.c
@@ -5248,6 +5248,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 60448600e24..20ab7848e6b 100644
--- a/gcc/d/dmd/expression.h
+++ b/gcc/d/dmd/expression.h
@@ -807,6 +807,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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-28 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 11:50 [gcc r10-10004] d: Change in DotTemplateExp type semantics leading to regression (PR101619) Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).