From 5203246984250193533
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7458762a2c3b301d
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-08-22 14:50:01 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: brangdon@cix.co.uk (Dave Harris)
Newsgroups: comp.std.c++
Subject: Re: Are literals const?
Date: Wed, 22 Aug 2001 21:49:37 GMT
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <memo.20010822222216.55863D@brangdon.madasafish.com>
References: <7dc3b1ea.0108220617.421ee131@posting.google.com>
Reply-To: brangdon@cix.co.uk
X-Trace: mail2news.demon.co.uk 998516981 mail2news:11340 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Orig-NNTP-Posting-Host: host213-1-23-254.webport-cl2-hg8.ilford.mdip.bt.net (213.1.23.254)
X-Orig-X-Trace: fu-berlin.de 998515218 12654087 213.1.23.254 (16 [57443])
Lines: 67
Xref: archiver1.google.com comp.std.c++:7082

pdimov@mmltd.net (Peter Dimov) wrote (abridged):
> What do you think about this piece of code:
> 
> int main()
> {
>   int const & r = 5;
>   const_cast<int &>(r) = 6;
> }
> 
> Is this legal? I think that it is.

I think it is too. The first line is, the second line is and I don't see 
any undefined behaviour. The type of 5 is (int), not (const int).


> Literals aren't const (they are about 90% const, but not 100% const.)

I think the reference is bound to a temporary, not a literal. I don't 
think r is a compile-time constant (just as well given we can assign to 
it). Eg:

    int const &r = 1;
    
    switch (j) {
    case r:         // Error - not a constant.
    }

However, I don't know when and how it stops being a literal.


> Do we _really_ need non-const literals and rvalues (of built-in
> types)?

Yes. I'd prefer to minimise the differences between built-in types and 
class types. Eg:

    class Complex {
    public:
         Complex( int i, int j=0 );
         //...
    };

    Complex const &r = 1;
    const_cast<Complex &>(r) = 2;

This is more or less reasonable for class types, so it should be permitted 
for built-in types too, for the sake of templates:

    template <typename T>
    void demo() {
        T const &r = 1;
        const_cast<T &>( r ) = 2;
    }

Unless there is a strong reason to have a difference. Is there?

  Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
      brangdon@cix.co.uk      |   And close your eyes with holy dread,
                              |  For he on honey dew hath fed
 http://www.bhresearch.co.uk/ |   And drunk the milk of Paradise."

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]



