Fix warning in posix/tst-getopt_long1.c
Joseph Myers
joseph@codesourcery.com
Tue Nov 25 23:53:00 GMT 2014
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.
diff --git a/posix/tst-getopt_long1.c b/posix/tst-getopt_long1.c
index e0ecd12..daabcc6 100644
--- a/posix/tst-getopt_long1.c
+++ b/posix/tst-getopt_long1.c
@@ -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);
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Libc-alpha
mailing list