This is the mail archive of the gcc@gcc.gnu.org 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


On Mon, 27 Oct 2014, Martin Uecker wrote:

> 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 think that is what's relevant.  (The wording you quote seems to be the 
C++11 (and C++98/C++03) wording; N3797 has "An array type whose elements 
are cv-qualified is also considered to have the same cv-qualifications as 
its elements."; the final C++14 standard doesn't yet seem to be 
available.)

> 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.

That code clearly can't have a pedwarn (as it's valid C, it mustn't have 
an error with -pedantic-errors).  And it would clearly be fine for it to 
be diagnosed with -Wc++-compat.  Warnings (not pedwarns) by default, with 
some option to disable them, could be considered if it's unlikely people 
will intentionally do this in C.

-- 
Joseph S. Myers
joseph@codesourcery.com


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