🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1462

Re: Type System

#1462
From: Jim Adcock
Date: Tue, 12 Jan 1993 21:45
34 lines
1626 bytes
In article <1993Jan9.001948.28388@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
>In article <C0Iy9o.9x@frumious.uucp>, pat@frumious.uucp (Patrick Smith) writes:
||> |	If an lvalue has non-const type,
||> |	then it refers to a mutable object.
||> 
||> There is another loophole. :-(
||> But it's (I hope) an unusual type of situation. :-)
||> 
||>    struct A { A(); /*...*/ };
||>    A* pa;
||>    A::A { pa = this; }
||> 
||>    void f() {
||>       const A a;
||>       // Now pa has non-const type but points to an immutable object.
||>    }
|
|You're right.  I knew about that loophole, but forgot about it when
|I posted my original item.  If anyone has ideas for a clean way
|to close this loophole, I'd be interested to hear them.  

A* pa;

A::A() const
{
	pa = this; // compile-time error: non-const ptr to const object
}

Such a const ctor can only give its members or base parts values via
the colon section initializers.  Members cannot be changed within the
body of the constructor.  For backwards compatibility, if you don't
declare a const ctor, then the loophole would be allowed to continue
in ctors of that class, and in which case members could continue to
be changed within the body of the ctor.
Technical Details
Message-ID: <1993Jan12.214547.20528@microsoft.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad
References: <1993Jan4.194318.5340@lucid.com> <C0Iy9o.9x@frumious.uucp> <1993Jan9.001948.28388@lucid.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad
From: jimad@microsoft.com (Jim Adcock)
Subject: Re: Type System
Message-ID: <1993Jan12.214547.20528@microsoft.com>
Date: 12 Jan 93 21:45:47 GMT
Organization: Microsoft Corporation
References: <1993Jan4.194318.5340@lucid.com> <C0Iy9o.9x@frumious.uucp> <1993Jan9.001948.28388@lucid.com>
Lines: 34