https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120455

            Bug ID: 120455
           Summary: char** and -Wincompatible-pointer-types
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lavr at ncbi dot nlm.nih.gov
  Target Milestone: ---

Please consider the following code

$ cat incompat.c
void func(const char* const* str)
{
    return;
}


int main(int argc, char** argv)
{
    func(argv + 1);
}


GCC throws the following warning (which is bogus IMO, because the implicit
conversion requires to totally const the referenced object (all char pointers
and their contents -- strings, in func).


$ gcc -Wall -c incompat.c
incompat.c: In function 'main':
incompat.c:9:15: warning: passing argument 1 of 'func' from incompatible
pointer type [-Wincompatible-pointer-types]
    9 |     func(argv + 1);
      |          ~~~~~^~~
      |               |
      |               char **
incompat.c:1:30: note: expected 'const char * const*' but argument is of type
'char **'
    1 | void func(const char* const* str)
      |           ~~~~~~~~~~~~~~~~~~~^~~


Meanwhile compiling with the C++ compiler generates no warning, and that's what
should be expected.

$ g++ -Wall -c incompat.c


The above warning bites badly in GCC14 where it has become an error instead. 
IDK why this compiler defect survived for so long, because obviously constness
conversion should have been allowed, as it is for (char* -> const char*).


The problem that the defect remained unfixed, now causes the otherwise valid
code to break the builds (yes, I modified the code to put #pragmas around the
supposedly "bad" places, but that does not make the code to look any better).


Can this please be addressed?

Reply via email to