AW: A: a new bug to old plain C

<[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
> -----Ursprüngliche Nachricht-----
> Von: Gcc-help <[email protected]> Im Auftrag von
> Jonathan Wakely via Gcc-help
> Gesendet: Freitag, 21. November 2025 12:47
> An: Chris S <[email protected]>
> Cc: Александр Поваляев <[email protected]>; gcc-help <gcc-
> [email protected]>
> Betreff: Re: A: a new bug to old plain C
> 
> On Fri, 21 Nov 2025 at 03:25, Chris S via Gcc-help <[email protected]>
> wrote:
> >
> > You're applying two consts to the same thing, so it's an error.
> 
> No, that's not happening here.
> 
> The explanation is
> https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion
> 
> >
> > "Const int" and "int const" are the same (look up East vs West const),
> > but "const int const" is an error.  Declaring a pointer to that
> > invalid type declaration is still invalid.
> >
> > On Thu, Nov 20, 2025, 5:27 PM Александр Поваляев via Gcc-help <
> > [email protected]> wrote:
> >
> > > struct zzz {
> > > unsigned x, y;
> > > };
> > >
> > > void square(struct zzz ** arr_of_ptr, unsigned count) {
> > >
> > > *// The first "const" produce an error (not a warning) within some
> > > GCC toolchains, for example ARM GCC trunk (linux), see goldbolt.org
> > > <http://goldbolt.org>*
> > > struct zzz const * const * const end_of_arr = arr_of_ptr + count;
> > >
> > > *// Without the first const "struct zzz * const * const end_of_arr =
> > > arr_of_ptr + count;" it works fine!!!*
> > >
> > > }
> > >
> > > Respectfully,
> > > Aleksandr G Povaliaev.
> > >

Consider:

char const * foo1(char * x) {
    char const * y = x;
    *x = 'a';
    return y;
}

char const ** foo2(char ** x) {
    char const ** y = x;
    **x = 'a';
    return y;
}

typedef char * cp;
cp const * foo3(cp * x) {
    cp const * y = x;
    **x = 'a';
    return y;
}

All three should compile fine, but one does not. 
It is not consistent.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.