https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81233
Bug ID: 81233
Summary: --Wdiscarded-qualifiers and
Wincompatible-pointer-types missing important detail
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The -Wdiscarded-qualifiers and -Wincompatible-pointer-types warnings (and
possibly others like these two) point out incompatibilities in expressions
involving conversions between incompatible pointer types but neglect to mention
the actual types of the pointer operands or where they are declared. For
example, imagine that in the program below the struct is defined in some header
file far removed from the assignment that triggers the warning. The lack of
detail makes it difficult to tell what the expected types are and what the
appropriate fix is.
$ cat x.c && gcc -S -Wall -xc x.c
struct S { int *p; char *q; const char *r; };
void f (struct S *s)
{
s->p = s->q;
s->q = s->r;
}
x.c: In function ‘f’:
x.c:5:8: warning: assignment from incompatible pointer type
[-Wincompatible-pointer-types]
s->p = s->q;
^
x.c:6:8: warning: assignment discards ‘const’ qualifier from pointer target
type [-Wdiscarded-qualifiers]
s->q = s->r;
^
In contrast to GCC, Clang issues the following messages:
t.c:5:8: warning: incompatible pointer types assigning to 'int *' from 'char *'
[-Wincompatible-pointer-types]
s->p = s->q;
^ ~~~~
t.c:6:8: warning: assigning to 'char *' from 'const char *' discards qualifiers
[-Wincompatible-pointer-types-discards-qualifiers]
s->q = s->r;
^ ~~~~