[Bug c/20230] GCC generates non-compliant warnings for qualifier promotion

joseph at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 28 10:00:00 GMT 2005

------- Additional Comments From joseph at codesourcery dot com  2005-02-27 22:30 -------
Subject: Re:  GCC generates non-compliant warnings for qualifier

On Sun, 27 Feb 2005, kmk at ssl dot org wrote:

> 1. A pointer is a derived type.
> 2. A derived type is not qualified by the qualifiers (if any) of the type from
> which it is derived.
> 3. For any qualifier q, a POINTER to a non-q-qualified type may be converted to
> a pointer to the q-qualified version of the type. [emphasis mine; note that a
> pointer is, by itself, a derived type which does not inherit any qualifiers---so
> what]

Indeed, a pointer to non-qualified "char *" may be converted to a pointer 
to qualified "char *".  For example, "char **" or "char **const" may be 
converted to "char *const *" or "char *volatile *const restrict".  But 
"const char *" isn't a qualified version of "char *"; "char *" and "const 
char *" are entirely distinct unqualified types.  So "char **" may not be 
converted to "const char *const *", because they are pointers to distinct 
unqualified types, not pointers to qualified and unqualified versions of 
the same type.

Your misconception appears to be that "const char *" is a qualified 
version of "char *".  It isn't.  They are incompatible unqualified types.  
Similarly, "const char *const *" is not a qualified version of "char **".

> 4. A pointer to a pointer is itself a pointer.
> 5. The C standard, unlike C++, does not further restrict qualifier promotion of
> multi-level pointers---in fact, it is completely silent on the issue.

It doesn't need to discuss the issue, as it follows from the definitions 
in the standard.  There is *no* concept of multi-level pointers in the 
standard; just that of pointers, derived from a type which may or may not 
be a pointer.



More information about the Gcc-bugs mailing list