From patchwork Tue Nov 25 23:53:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 3919 Received: (qmail 30587 invoked by alias); 25 Nov 2014 23:53:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 30569 invoked by uid 89); 25 Nov 2014 23:53:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Tue, 25 Nov 2014 23:53:29 +0000 From: Joseph Myers To: Subject: Fix warning in posix/tst-getopt_long1.c Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 * 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);