Fix warning in posix/tst-getopt_long1.c
Commit Message
This patch fixes a "discards qualifiers" warning in
posix/tst-getopt_long1.c. glibc is built with -Wwrite-strings,
meaning a char * cannot be initialized with a string constant; because
the array of char * gets passed to getopt_long, expecting char *const
*, the array can't be changed to one of const char *, hence the use of
compound literals to provide non-const character arrays initialized
with the strings, as explained in the comment added.
Tested for x86_64.
2014-11-25 Joseph Myers <joseph@codesourcery.com>
* posix/tst-getopt_long1.c (do_test): Use compound literals in
argv array instead of directly using string constants.
Comments
Ping. This patch
<https://sourceware.org/ml/libc-alpha/2014-11/msg00741.html> is pending
review.
The strings won't be modified. So why not just add (char *) casts?
@@ -39,7 +39,11 @@ do_test (void)
return 1;
}
- char *argv[] = { "program", "--on" };
+ /* Because getopt_long takes a char *const * argument, this array
+ cannot be const char *[]; because glibc uses -Wwrite-strings, the
+ compound literals are needed to provide pointers non-const
+ character arrays, instead of using string literals directly. */
+ char *argv[] = { (char []) { "program" }, (char []) { "--on" } };
int argc = 2;
int c = getopt_long (argc, argv, "12345", opts, NULL);