Topic: Qualification conversions


Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/08/08
Raw View
"Michael Rice" <mpr@absoft.com> writes:

>Section 4.4 [conv.qual] para 3 of the May 1996 draft states:
[...]
>   .mc|T1 is cv1,0 pointer to cv1,1 pointer to ... cv1,n pointer to T.mc
>
>Questions:
>
>1.  What does the notation .mc|T1 mean?  And where in the draft is this
>    notation explained or is it a typesetting error?

It is a typesetting error.  My copy of the same May 1996 draft reads

 T1 is cv1,0 pointer to cv1,1 pointer to ... cv1,n pointer to T.

>Next is the following example which should (apparently) be illegal:
>
>const char* c = 'c';
>char* pc;
>const char** pcc = & pc;        // 1 (not allowed)
>*pcc = &c;
>*pc = 'C';   // modifies a const object
>
>Here T1 is converted to T2:
>T1 is pointer to pointer to "char"
>
>T2 is pointer to pointer to "const char"
>
>So there does not exist a T that makes these types "similar" as
>"char" is not the same as "const char".
>
>Is this reasoning correct?

Yes :-(

>How about this:
>
>char c = 'x';
>char* pc = &c;
>const char *const *pcc = &pc;
>
>T1 is converted to T2:
>
>T1 is pointer to pointer to "char"
>T2 is pointer to const pointer to "const char"
>
>Here again "char" and "const char" are different so these pointers
>are not similar?

Yes :-(

I think you've spotted a bug in the working paper.
Your second code example is precisely the sort of thing
that this part of the standard was intended to allow, I think.
I think the standard should say something like

    Two pointer types T1 and T2 are *similar* if there exists a type T and
    integer N>0 such that:

            T1 is cv1,0 pointer to cv1,1 pointer to ...
  to cv1,n-1 pointer to cv1,n T
          ^^            ^^^^^
    and

            T2 is cv2,0 pointer to cv2,1 pointer to ...
      to cv2,n-1 pointer to cv2,n T
   ^^            ^^^^^

rather than what the current draft says.
(The ^^ symbols denote newly inserted text.)

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Michael Rice" <mpr@absoft.com>
Date: 1996/08/08
Raw View
Section 4.4 [conv.qual] para 3 of the May 1996 draft states:

A conversion can add cv-qualifiers at levels other than the first
in multi-level pointers, subject to the following rules: 49)

  Two pointers types T1 and T2 are similar if there exists a type T
  and integer N > 0 such that:

   .mc|T1 is cv1,0 pointer to cv1,1 pointer to ... cv1,n pointer to T.mc
and
   .mc|T2 is cv2,0 pointer to cv2,1 pointer to ... cv2,n pointer to T.mc

where each cvi,j is const, volatile, const volatile, or nothing.

Questions:

1.  What does the notation .mc|T1 mean?  And where in the draft is this
    notation explained or is it a typesetting error?

2.  What does the notation T.mc mean?  And where is the draft is this
    notation explained or is it a typesetting error?

Continuing:

And expression of type T1 can be converted to T2 if and only if the following
conditions are satisfied:

  -- the pointer types are similar
  -- for every j>0, if const is in cv1,j then const is in cv2,j,
     and similarly for volatile.
  -- if the cv1,j and cv2,j are different, then const is in every
     cv2,k for 0<k<j.

Next is the following example which should (apparently) be illegal:

const char* c = 'c';
char* pc;
const char** pcc = & pc;        // 1 (not allowed)
*pcc = &c;
*pc = 'C';   // modifies a const object

Here T1 is converted to T2:
T1 is pointer to pointer to "char"

T2 is pointer to pointer to "const char"

So there does not exist a T that makes these types "similar" as
"char" is not the same as "const char".

Is this reasoning correct?

How about this:

char c = 'x';
char* pc = &c;
const char *const *pcc = &pc;

T1 is converted to T2:

T1 is pointer to pointer to "char"
T2 is pointer to const pointer to "const char"

Here again "char" and "const char" are different so these pointers
are not similar?

Thanks.

--
Mike Rice (mpr@absoft.com)
Absoft Corporation


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]