From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id DA9513858D34 for ; Fri, 26 Jun 2020 13:05:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DA9513858D34 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-111-j-1HoN0tNC6YMdJnZrgKDQ-1; Fri, 26 Jun 2020 09:05:03 -0400 X-MC-Unique: j-1HoN0tNC6YMdJnZrgKDQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FBD387950C for ; Fri, 26 Jun 2020 13:05:02 +0000 (UTC) Received: from blade.nx (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70A0610016DA; Fri, 26 Jun 2020 13:05:02 +0000 (UTC) Received: from blade.com (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 8C653816CCA9; Fri, 26 Jun 2020 14:05:01 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [PATCH v2] Fix -Wstring-compare testcase build failure Date: Fri, 26 Jun 2020 14:05:00 +0100 Message-Id: <1593176700-16489-1-git-send-email-gbenson@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-15.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jun 2020 13:05:11 -0000 Pedro Alves wrote: > On 6/23/20 3:57 PM, Gary Benson via Gdb-patches wrote: > > Hi all, > > > > Clang fails to compile the file gdb/testsuite/gdb.cp/try_catch.cc > > with the following error: > > warning: result of comparison against a string literal is > > unspecified (use strncmp instead) [-Wstring-compare] > > > > This patch replaces the string literal with a pointer, to avoid > > the error. > > > > Is it ok to commit? > > Hmm, no, I don't think so. [snip] > invalid_argument stores a copy of the string, so with or > without your patch, that (obj.what() != "gdb.1") comparison > is returning false. Thus the "test &= false;" statement is > executing. Ah, I had not realized the string was copied, I think I thought the compiler was complaining about something else. > IOW, that Clang warning found a bug in the test program... > > The fix should be to use strcmp instead. > > And also, please add a market at the "return 0;" line, > let the program run to it, and then add a gdb_test checking > that "test" is still true at that point. Ok. How about this? -- Clang fails to compile the file gdb/testsuite/gdb.cp/try_catch.cc with the following error: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare] This commit fixes the error, replacing the pointer comparison with a call to strcmp. This commit also adds a final check: the test program is run to the final return statement, and the value of "test" is checked to ensure it is still "true" at that point. gdb/testsuite/ChangeLog: * gdb.cp/try_catch.cc: Include string.h. (main): Replace comparison against string literal with strcmp, avoiding build failure with -Wstring-compare. Add "marker test-complete". * gdb.cp/try_catch.exp: Run the test to the above marker, then verify that the value of "test" is still true. --- gdb/testsuite/ChangeLog | 9 +++++++++ gdb/testsuite/gdb.cp/try_catch.cc | 5 +++-- gdb/testsuite/gdb.cp/try_catch.exp | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.cp/try_catch.cc b/gdb/testsuite/gdb.cp/try_catch.cc index 4c4add2..5f454f4 100644 --- a/gdb/testsuite/gdb.cp/try_catch.cc +++ b/gdb/testsuite/gdb.cp/try_catch.cc @@ -18,6 +18,7 @@ #include #include #include +#include enum region { oriental, egyptian, greek, etruscan, roman }; @@ -129,8 +130,8 @@ int main() } catch (exception& obj) { - if (obj.what() != "gdb.1") // marker 3-catch + if (strcmp (obj.what(), "gdb.1") != 0) // marker 3-catch test &= false; } - return 0; + return 0; // marker test-complete } diff --git a/gdb/testsuite/gdb.cp/try_catch.exp b/gdb/testsuite/gdb.cp/try_catch.exp index fb53294..e4da885 100644 --- a/gdb/testsuite/gdb.cp/try_catch.exp +++ b/gdb/testsuite/gdb.cp/try_catch.exp @@ -63,5 +63,8 @@ gdb_continue_to_breakpoint "marker 3-throw" gdb_breakpoint [gdb_get_line_number "marker 3-catch"] gdb_continue_to_breakpoint "marker 3-catch" +gdb_breakpoint [gdb_get_line_number "marker test-complete"] +gdb_test "p test" "= true" + gdb_exit return 0 -- 1.8.3.1