From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id B50B3387086A for ; Tue, 23 Jun 2020 15:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B50B3387086A Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-TvzPLUyANbqTkIZ6PYknrA-1; Tue, 23 Jun 2020 11:57:35 -0400 X-MC-Unique: TvzPLUyANbqTkIZ6PYknrA-1 Received: by mail-wm1-f69.google.com with SMTP id p24so4923836wmc.1 for ; Tue, 23 Jun 2020 08:57:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RxG9eCmFFnvlJae5Pge2696SZUGSpf9qSHvRJwF7+SM=; b=bqwElxZZxiO2UjMrJfUM6tTWVs0eRyLZ0PmhPkp9nheySGuaGdYmoLszmMqSSlmiY4 c13MUDohmNbOOGCBlz0j59y/dTN0o/nJ3fWIjvsxZ3qyr++p70kXKwflpkLWA28CAC6P SsEEJCUS63oYzc0PtiFQUz9ooSLv01Ird4uAR3sXrwqrp49RG6V/FufWwcJ1BvxJBxwl ODsprZZsFuiGqdRVTbTxoIZDTpXa9FfVZQWLyhp+KjPfN3YeAmNVVqUDd0QoWp9/XLe0 I5HlMoBFB8TaQo0F5ulQB+GRZtZ6K14Kpumn9J1Yi/er/YtoFOM8yFGFLt7dJwjHBc7A 095A== X-Gm-Message-State: AOAM530uM+c+IIEG4T3ZP1j+ozDsQ2GRZzlX8jnNwTU6lYanjhPxmb5R 3Eyg0/lUDY8GzG1bx0u21zy9PAPo29soD+NF6Fr6Yph8fvUVIro9W/ygqY4009cu6WaOz9nulIM n71b2qSN59yBMeuGgFe0o0Q== X-Received: by 2002:adf:e287:: with SMTP id v7mr22344099wri.329.1592927852011; Tue, 23 Jun 2020 08:57:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9wZbTlKJomLPt4sNApKbTjyTVcNFVmre39UW4aYsfekTqAmnPw5kryYTau6YdmDnL7cRBbQ== X-Received: by 2002:adf:e287:: with SMTP id v7mr22344082wri.329.1592927851849; Tue, 23 Jun 2020 08:57:31 -0700 (PDT) Received: from ?IPv6:2001:8a0:f922:c400:56ee:75ff:fe8d:232b? ([2001:8a0:f922:c400:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id u10sm4231765wml.29.2020.06.23.08.57.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jun 2020 08:57:31 -0700 (PDT) Subject: Re: [PATCH] Fix -Wstring-compare testcase build failure To: Gary Benson , gdb-patches@sourceware.org References: <1592924228-13346-1-git-send-email-gbenson@redhat.com> From: Pedro Alves Message-ID: Date: Tue, 23 Jun 2020 16:57:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1592924228-13346-1-git-send-email-gbenson@redhat.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Tue, 23 Jun 2020 15:57:38 -0000 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. > > // 3 use standard library > using namespace std; > + const char *throwme = "gdb.1"; > try > { > if (j < 100) > - throw invalid_argument("gdb.1"); // marker 3-throw > + throw invalid_argument(throwme); // marker 3-throw > } > catch (exception& obj) > { > - if (obj.what() != "gdb.1") // marker 3-catch > + if (obj.what() != throwme) // marker 3-catch > test &= false; > } > return 0; 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. 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. Thanks, Pedro Alves