Jump to page: 1 2
Thread overview
[Issue 2094] New: transitive const can be broken easily
May 11, 2008
d-bugmail
Jun 17, 2008
d-bugmail
Jun 17, 2008
d-bugmail
Jun 18, 2008
d-bugmail
Jun 18, 2008
d-bugmail
Jun 18, 2008
d-bugmail
Jun 18, 2008
d-bugmail
Jun 19, 2008
d-bugmail
Jun 19, 2008
d-bugmail
Jun 19, 2008
d-bugmail
Oct 06, 2008
d-bugmail
Oct 07, 2008
d-bugmail
Oct 07, 2008
d-bugmail
Oct 08, 2008
d-bugmail
May 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094

           Summary: transitive const can be broken easily
           Product: D
           Version: 2.012
          Platform: PC
               URL: http://www.digitalmars.com/webnews/newsgroups.php?art_gr
                    oup=digitalmars.D&article_id=71465
        OS/Version: Windows
            Status: NEW
          Keywords: spec
          Severity: normal
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: terranium@yandex.ru


class A
{
        private int[] Xrg;

        int[] rg() const
        {
                return Xrg;
        }
}

void f(invariant A a)
{
        a.rg[0]=0;
}


-- 

June 17, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #1 from terranium@yandex.ru  2008-06-17 09:40 -------
C++ solution: forces rg to have return type const int[]


-- 

June 17, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #2 from 2korden@gmail.com  2008-06-17 09:54 -------
It shouldn't be able to compile and in fact it doesn't (tested with DMD2.013):
Error: cannot implicitly convert expression (this.Xrg) of type const(int[]) to
int[]


-- 

June 18, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #3 from terranium@yandex.ru  2008-06-18 02:09 -------
So one should write two getters: const and non-const?


-- 

June 18, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #4 from wbaxter@gmail.com  2008-06-18 05:28 -------
(In reply to comment #3)
> So one should write two getters: const and non-const?
> 

That's generally how it's done in C++, yes.
But in D you may need three, actually.  invariant, const, and non-const.
There was much discussion about creating some rules so that D doesn't require
that kind of repetition, but Walter never gave any of the ideas a nod as far as
I know.


-- 

June 18, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094


2korden@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #5 from 2korden@gmail.com  2008-06-18 06:11 -------
Shall we close this one?


-- 

June 18, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094


braddr@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #6 from braddr@puremagic.com  2008-06-18 11:18 -------
No.  invariantness if f's arg isn't being preserved, so this is a hole that Walter should see.  I've reopened.


-- 

June 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #7 from wbaxter@gmail.com  2008-06-19 01:05 -------
I was just browsing through WalterAndrei.pdf from last year's D conference, when I noticed the "return" storage class.  I had forgotten about that one.

So I was wrong about Walter not having endorsed any particular solution to the redundant const methods problem.  The solution he proposed at the D conference was to have something like:

   const(char[]) capitalize(return const(char[]) s) { ... }


-- 

June 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #8 from terranium@yandex.ru  2008-06-19 02:42 -------
(In reply to comment #4)
> But in D you may need three, actually.  invariant, const, and non-const.
Isn't unvariant implicitly castable to const?

(In reply to comment #7)
> I was just browsing through WalterAndrei.pdf from last year's D conference, when I noticed the "return" storage class.  I had forgotten about that one.
It adds dependency on argument, but how about dependency on the hidden argument - this.

(In reply to comment #6)
> No.  invariantness if f's arg isn't being preserved, so this is a hole that Walter should see.  I've reopened.
I think, if my sample doesn't compile, this bugreport is no longer valid or severity could be canged to RFE, I'm not sure, what you want.


-- 

June 19, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2094





------- Comment #9 from wbaxter@gmail.com  2008-06-19 07:19 -------
(In reply to comment #8)
> (In reply to comment #4)
> > But in D you may need three, actually.  invariant, const, and non-const.
> Isn't unvariant implicitly castable to const?

If you're hoping to be able to assign the result to an invariant then you'll need an invariant flavor of it.


-- 

« First   ‹ Prev
1 2