This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] warning about const multidimensional array as function parameter

Jonathan Wakely <>:

> On 27 October 2014 13:10, Joseph S. Myers wrote:
> > On Sat, 25 Oct 2014, Martin Uecker wrote:
> >
> >> Strictly speaking the C standard considers such pointers to be
> >> incompatible. This seems to be an unintentional consequence
> >> of how qualifiers are always attached to the element type.
> >> (I am trying to get the standard revised too.) The new
> >> behaviour should also be more compatible with C++.
> >
> > What is the exact difference in wording in the C++ standard that results
> > in this difference in semantics?
> See 4.4 [conv.qual] in

Note that this doesn't talk explicitly about arrays
and that C++ keeps the notion that qualifiers are
always attached to the element type:

3.9.3(2) ... Any cv-qualifiers applied to an array type
affect the array element type, not the array type (8.3.4).


3.9.3(5) ...
Cv-qualifiers applied to an array type attach to the
underlying element type, so the notation âcv T,â where
T is an array type, refers to an array whose elements
are so-qualified. Such array types can be said to be
more (or less) cv-qualified than other types based on
the cv-qualification of the underlying element types.

I *believe* (but I don't know the C++ standard very well)
that all the magic is in the wording "can be said to be more 
(or less) cv-qualified" which makes the conversion rules work 
for arrays with constant element type "as if" the array itself
had the qualifier.

4.4 Qualification conversions
4.4(1) "A prvalue of type âpointer to cv1 Tâ can be converted
to  a prvalue of type âpointer to cv2 Tâ if âcv2 Tâ is more
cv-qualified than âcv1 Tâ."

There is another issue in C which has the same underlying reason
(brought up by Tim Rentsch in comp.std.c) as shown in the following
example (this is legal C and compiles without a warning (gcc) but is
illegal in C++):

#include <string.h>
static const int x[5] = { 0 };
void test(void)
        memset(&x, 0, sizeof(x));

I did not try to address this in the patch because it would make legal
code have a warning, but one could think about it.


PS: Joseph, thank you for reviewing the patch.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]