Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 8366 - Overriding const member function in conjunction with mutable overload causes a strange error #1042

Merged
merged 1 commit into from about 1 year ago

3 participants

Hara Kenji Daniel Murphy Walter Bright
Hara Kenji
Collaborator
9rnsr commented July 10, 2012

http://d.puremagic.com/issues/show_bug.cgi?id=8366

We MUST kill attribute inference with const. To implement it correctly without breaking overriding and overloading features, re-scanning and arrangement of vtbl entries is needed in the end of ClassDeclaration::semantic, it will decrease compile speed.

I think that is a big drawbacks than the benefit.

Hara Kenji
Collaborator
9rnsr commented July 10, 2012

I've posted supplemental pulls for druntime and phobos.
D-Programming-Language/druntime#272
D-Programming-Language/phobos#680

We should merge the two before this.

Hara Kenji
Collaborator

Updated test code.

Daniel Murphy
Collaborator

FWIW, I support this pull.
@WalterBright, @andralex ?

Hara Kenji
Collaborator

@WalterBright : could you please review this, and merge into master.

fix Issue 8366 - Overriding const member function in conjunction with…
… mutable overload causes a strange error

We MUST kill attribute inference with const. To implement it correctly without breaking overriding and overloading features, re-scanning and arrangement of vtbl entries is needed in the end of Classdeclaration::semantic, it will decrease compile speed.
I think that is a big drawbacks than the benefit.
de9e8b3
Walter Bright WalterBright merged commit 2cab1b0 into from March 06, 2013
Walter Bright WalterBright closed this March 06, 2013
Hara Kenji
Collaborator
9rnsr commented March 06, 2013

Thanks very much, @WalterBright ! This is good direction.

Deleted user Unknown referenced this pull request from a commit December 24, 2013
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 25, 2013
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 25, 2013
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 25, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 14, 2013
fix Issue 8366 - Overriding const member function in conjunction with…
… mutable overload causes a strange error

We MUST kill attribute inference with const. To implement it correctly without breaking overriding and overloading features, re-scanning and arrangement of vtbl entries is needed in the end of Classdeclaration::semantic, it will decrease compile speed.
I think that is a big drawbacks than the benefit.
de9e8b3
This page is out of date. Refresh to see the latest.
4  src/mtype.c
@@ -5209,11 +5209,15 @@ int Type::covariant(Type *t, StorageClass *pstc)
5209 5209
      */
5210 5210
     if (!MODimplicitConv(t2->mod, t1->mod))
5211 5211
     {
  5212
+#if 0//stop attribute inference with const
5212 5213
         // If adding 'const' will make it covariant
5213 5214
         if (MODimplicitConv(t2->mod, MODmerge(t1->mod, MODconst)))
5214 5215
             stc |= STCconst;
5215 5216
         else
5216 5217
             goto Lnotcovariant;
  5218
+#else
  5219
+        goto Ldistinct;
  5220
+#endif
5217 5221
     }
5218 5222
 
5219 5223
     /* Can convert pure to impure, and nothrow to throw
52  test/runnable/testconst.d
@@ -2744,6 +2744,57 @@ void test8212()
2744 2744
 }
2745 2745
 
2746 2746
 /************************************/
  2747
+// 8366
  2748
+
  2749
+class B8366
  2750
+{
  2751
+    bool foo(in Object o) const { return true; }
  2752
+}
  2753
+
  2754
+class C8366a : B8366
  2755
+{
  2756
+    bool foo(in Object o)              { return true; }
  2757
+  override
  2758
+    bool foo(in Object o) const        { return false; }
  2759
+    bool foo(in Object o) immutable    { return true; }
  2760
+    bool foo(in Object o) shared       { return true; }
  2761
+    bool foo(in Object o) shared const { return true; }
  2762
+}
  2763
+
  2764
+class C8366b : B8366
  2765
+{
  2766
+    bool foo(in Object o)              { return false; }
  2767
+    alias super.foo foo;
  2768
+    bool foo(in Object o) immutable    { return false; }
  2769
+    bool foo(in Object o) shared       { return false; }
  2770
+    bool foo(in Object o) shared const { return false; }
  2771
+}
  2772
+
  2773
+void test8366()
  2774
+{
  2775
+    {
  2776
+              C8366a mca = new C8366a();
  2777
+        const C8366a cca = new C8366a();
  2778
+              B8366  mb  = mca;
  2779
+        const B8366  cb  = cca;
  2780
+        assert(mca.foo(null) == true);
  2781
+        assert(cca.foo(null) == false);
  2782
+        assert(mb .foo(null) == false);
  2783
+        assert(cb .foo(null) == false);
  2784
+    }
  2785
+    {
  2786
+              C8366b mcb = new C8366b();
  2787
+        const C8366b ccb = new C8366b();
  2788
+              B8366  mb  = mcb;
  2789
+        const B8366  cb  = ccb;
  2790
+        assert(mcb.foo(null) == false);
  2791
+        assert(ccb.foo(null) == true);
  2792
+        assert(mb .foo(null) == true);
  2793
+        assert(cb .foo(null) == true);
  2794
+    }
  2795
+}
  2796
+
  2797
+/************************************/
2747 2798
 // 8408
2748 2799
 
2749 2800
 template hasMutableIndirection8408(T)
@@ -3001,6 +3052,7 @@ int main()
3001 3052
     test8099();
3002 3053
     test8201();
3003 3054
     test8212();
  3055
+    test8366();
3004 3056
     test8408();
3005 3057
     test8688();
3006 3058
     test9046();
2  test/runnable/xtest46.d
@@ -4943,7 +4943,7 @@ class A158
4943 4943
 class B158 : A158
4944 4944
 {
4945 4945
     override void foo1() { }
4946  
-    override void foo2() { }
  4946
+    override void foo2() const { }
4947 4947
     override void foo3() { }
4948 4948
     override void foo4() { }
4949 4949
 }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.