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

joseph at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Sun Feb 27 18:47:00 GMT 2005


------- Additional Comments From joseph at codesourcery dot com  2005-02-27 13:05 -------
Subject: Re:  New: GCC generates non-compliant warnings for
 qualifier promotion

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

> "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; the values stored in the
> original and converted pointers shall compare equal." [section 6.3.2.3, paragraph 2]

All my references in what follows are to the standard itself, C99 as 
amended by TC1 and TC2.  Using drafts is a false economy.

> void safe_function(const char *const *s) { }
> 
> int main(void) {
> 
>   char *mystrings[2] = { "First string", "Second string" };
> 
> // This call warns, but should not:
>   safe_function(mystrings);

The constraints for function calls are not in 6.3.2.3, they are in 
6.5.2.2#2, which references the constraints for assignment in 6.5.16.1#1.

       6.5.16.1  Simple assignment

       Constraints

       [#1] One of the following shall hold:93)

         -- the  left  operand   has   qualified   or   unqualified
            arithmetic type and the right has arithmetic type;

Not applicable.

         -- the left operand has a qualified or unqualified version
            of a structure or union type compatible with  the  type
            of the right;

Not applicable.

         -- both  operands are pointers to qualified or unqualified
            versions of compatible types, and the type  pointed  to
            by  the left has all the qualifiers of the type pointed
            to by the right;

The type on the left is "const char *const *".  That on the right is "char 
**".  These are pointers to "const char * const" and "char *".  These 
types are qualified or unqualified versions of "const char *" and "char 
*".  (Qualification is defined in 6.2.5#25: each of "char *" and "const 
char *" has seven qualified versions, while plain "char *" and "const char 
*" are both unqualified types; note the last sentence of that paragraph, 
"A derived type is not qualified by the qualifiers (if any) of the type 
from which is is derived.", and the definition of pointer types as derived 
types in paragraph 20.)  "const char *" and "char *" are unqualified 
types which are not compatible: compatibility is defined in 6.2.7#1 and 
6.7.3#9 says when qualified types are compatible.  Note that "char" and 
"const char" are not compatible, because they don't have the same 
qualifiers, so "char *" and "const char *" are not compatible, and the 
unqualified version of "const char *const" is "const char *" not "char *" 
by the definition of qualification.

         -- one operand is a pointer to  an  object  or  incomplete
            type  and  the  other  is  a  pointer to a qualified or
            unqualified version of void, and the type pointed to by
            the  left has all the qualifiers of the type pointed to
            by the right;

Not applicable.

         -- the left operand is a pointer and the right is  a  null
            pointer constant; or

Not applicable.

         -- the  left  operand  has  type  _Bool and the right is a
            pointer.

Not applicable.

None of the above apply, so GCC diagnoses the constraint violation.  If 
you want C++ rules, GCC provides a C++ compiler.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20230



More information about the Gcc-bugs mailing list