[comp.lang.c++] What is the cv-qualifier of a reference?

ngo@tammy.harvard.edu (Tom Ngo) (04/03/91)

On March 25 I posted a question to which nobody replied.  Here it is
again, in shorter form:

[What I do understand]     A pointer can have a cv-qualifier, e.g.

                               int *const p;

                           here the cv-qualifier is "const" and it refers
                           to the pointer, NOT to the object pointed to.

[What I don't understand]  A reference can have a cv-qualifier, e.g.

                               int &const j;

                           What does const mean in this case?  What
                           restrictions are placed on j?

My original post, which I feel was more precisely worded, is included below.

===========================================================================
(Message unread:29)
Return-Path: ngo@tammy.harvard.edu
From: ngo@tammy.harvard.edu (Tom Ngo)
Newsgroups: comp.lang.c++
Subject: What?  A reference can have cv-qualifiers?
Date: 25 Mar 91 15:13:59 GMT
Distribution: comp
Organization: Harvard Chemistry Department


I'm confused.  I just read in ARM 8.2.2 [References]:

    In a declaration T D where D has the form

        & cv-qualifier-list-opt D1

    the type of the contained identifier is "... cv-qualifier-list
    reference to T."

I cannot imagine what the cv-qualifiers do!  In the case of a pointer,
we read ARM 8.2.1 [Pointers]:

    In a declaration T D where D has the form

        * cv-qualifer-list-opt D1

    the type of the contained identifier is "... cv-qualifer-list
    pointer to T."  The cv-qualifiers apply to the pointer and not to
    the object pointed to.

and of course that makes total sense.  But how could cv-qualifiers
apply to a reference?

    const int& i;       // reference to const int
    int &const j;       // const reference to int?

What restrictions are there on j?  We already know that j cannot be
made to refer to a different object since in ARM 8.4.3 [References] we
have 

    A variable declared to be a T& ... must be initialized .... A
    reference cannot be changed to refer to another object after
    initialization. 

I would appreciate responses by email, and I will summarize.  No doubt
I will be flooded by replies that say "No, no, you are totally
misunderstanding references!"

Thanks in advance...

--
  Tom Ngo
  ngo@harvard.harvard.edu
  617/495-1768 lab number, leave message
--
  Tom Ngo
  ngo@harvard.harvard.edu
  617/495-1768 lab number, leave message

rfg@NCD.COM (Ron Guilmette) (04/06/91)

In article <NGO.91Apr2153525@tammy.harvard.edu+ ngo@tammy.harvard.edu (Tom Ngo) writes:
+
+[What I don't understand]  A reference can have a cv-qualifier, e.g.
+
+                               int &const j;
+
+                           What does const mean in this case?  What
+                           restrictions are placed on j?

Tom,

Perhaps nobody answered your question because nobody knows what a
cv-qualified reference means (including Bjarne I think, although
I certainly *cannot* and *do not* speak for him).

Like you, others (including me) have been mystified by this question in
the past and have sought clarification.  To the best of my knowledge,
no clarification has been forthcomming from any quarter.

You can view this as either a problem or an opportunity.  It is a problem
if you really need the language to be precisely specified at this point
in time.  However it is an opportinity for you (and others) to join the
x3j16 standardization committee, make up your own "meaning" for cv-qualified
references, and then have lengthy arguments with other x3j16 members
about whether or not your "meaning" is either useful or necessary.  (It's
great fun if you're into that sort of thing.)

-- 

// Ron ("Shoot From The Hip") Guilmette
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// New motto:  If it ain't broke, try using a bigger hammer.