[Bug c/49748] New: char * const * cannot be assigned to char const * const *

2011-07-14 Thread gcc at misc dot lka.org.lu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49748

   Summary: char * const * cannot be assigned to char const *
const *
   Product: gcc
   Version: 4.4.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: g...@misc.lka.org.lu


Trying to assign a pointer value A with type "char * const *" into a variable B
declared as "char const * const * " triggers a warning, although the
const-yness of the type is _increased_ not decreased.

Such a thing may be needed when trying to call a function that displays a list
of strings:

void displayList(char const * const * list)
{
   /* display list */
}

The char const * declaration is needed if somewhere in the program, this
function is called with an array of static strings:

   char const  *list1[] = { "hello", "world", NULL };
   displayList(list1);


However, if elsewhere in the program, we want to call the function with a list
of _dynamically_ allocated strings, we get a "initialization from incompatible
pointer type" warning:
   char **list2;
   for(i=0; i< N; i++)
  list2[i] = strdup( some expression );

   ...
   displayList(list2);

   for(i=0; i

[Bug c/49748] char * const * cannot be assigned to char const * const *

2011-07-14 Thread gcc at misc dot lka.org.lu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49748

--- Comment #2 from Alain Knaff  2011-07-14 
17:38:59 UTC ---
Created attachment 24756
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24756
Test program for const warning bug

> the warning is correct, see http://c-faq.com/ansi/constmismatch.html

Thanks for this link. This does indeed confirm what I said, in much less words
than I needed. Moreover, it points out that the issue doesn't exist in C++.

However, it doesn't explain why the issue still present in C.

Any insights into this question?

If this is just to keep some paper-pushers happy, maybe we could keep the
current behavior as the default, but have a -W flag to make gcc mimic g++'s
behavior?