From patchwork Fri Jan 6 21:23:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 90233 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp9628447qgi; Fri, 6 Jan 2017 13:23:55 -0800 (PST) X-Received: by 10.98.83.193 with SMTP id h184mr72644523pfb.175.1483737835264; Fri, 06 Jan 2017 13:23:55 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b2si52397589pll.243.2017.01.06.13.23.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 13:23:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-445608-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-445608-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-445608-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=wrSkjkeCBsjk5LNV/ JHsIQL8sB6Wv8KHZ82kIyaHx6FUgq060cJKE8Uamofp3K1JvcVuCK66fs5GyalKC VlQoCvx+GLxtpeBcC1nj4hoSHOJ6Kpy7RE+ge9A4lCXS4NyOEt9qjZb88k7YZsun 9fpvsI/SVLb6671Yq2nmf2LoF0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=RPZQgCxSgx2WQ9G+7iTsz0O 9BIs=; b=BRUmiL8WmG0RXdIv9JBfx+dXPJ7gs3T+3pIlVTTWzIoPL7704e7kJrJ 15qJgIQ+GDi0eKoSFH6WqTiDgMskAGbZSSfzUYjG4W5v1M9BLjPPp8in2HtJvCx5 cdf+ah5uxcK0W7gWarh0xjth8Oh58cVfg/Ml2hBihbBX8BHY3buE= Received: (qmail 55433 invoked by alias); 6 Jan 2017 21:23:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 55402 invoked by uid 89); 6 Jan 2017 21:23:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=our X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Jan 2017 21:23:31 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87558C05678D; Fri, 6 Jan 2017 21:23:31 +0000 (UTC) Received: from localhost (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v06LNUru009952; Fri, 6 Jan 2017 16:23:31 -0500 Date: Fri, 6 Jan 2017 21:23:29 +0000 From: Jonathan Wakely To: Aditya Kumar Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, hiraditya@msn.com Subject: Re: [PATCH] improve string find algorithm Message-ID: <20170106212329.GK2966@redhat.com> References: <1481132816-31162-1-git-send-email-aditya.k7@samsung.com> <20170106133502.GB2966@redhat.com> <20170106203204.GI2966@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170106203204.GI2966@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) On 06/01/17 20:32 +0000, Jonathan Wakely wrote: >On 06/01/17 13:35 +0000, Jonathan Wakely wrote: >>I'm surprised we don't have any tests for this case, but apparently we >>don't, as your patch passes all our tests. > >My bad, we do have tests that FAIL with this patch, but only after a >'make clean' (otherwise the explicit instantiation definitions in the >library don't get rebuilt after applying the patch, so the tests use >the old code). > >FAIL: 21_strings/basic_string/operations/find/char/1.cc execution test >FAIL: 21_strings/basic_string/operations/find/wchar_t/1.cc execution test > >These fail on assert(s.find(s, 1) == std::string::npos) which gives >the wrong answer as explained in my previous mail. > >The infinite loop caused by this patch isn't caught by any existing >tests, so I'll add a check for that. Committed to trunk. commit b81b226d9eb336f205e5ac91fb8ab4bbbfaf2cb8 Author: Jonathan Wakely Date: Fri Jan 6 21:20:57 2017 +0000 Add more tests for std::basic_string::find * testsuite/21_strings/basic_string/operations/find/char/6.cc: New. * testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc: New. diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc new file mode 100644 index 0000000..6925fbb --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc @@ -0,0 +1,41 @@ +// 2017-01-06 Jonathan Wakely + +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// C++11 21.4.7.2 [string::find] basic_string find + +#include +#include + +// https://gcc.gnu.org/ml/libstdc++/2017-01/msg00021.html +void test01() +{ + typedef std::string string_type; + string_type::size_type npos = string_type::npos; + + string_type use = "aaa"; + string_type::size_type pos1 = use.find("ab"); + + VERIFY( pos1 == npos ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc new file mode 100644 index 0000000..eb3463d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc @@ -0,0 +1,41 @@ +// 2017-01-06 Jonathan Wakely + +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// C++11 21.4.7.2 [string::find] basic_string find + +#include +#include + +// https://gcc.gnu.org/ml/libstdc++/2017-01/msg00021.html +void test01() +{ + typedef std::wstring string_type; + string_type::size_type npos = string_type::npos; + + string_type use = L"aaa"; + string_type::size_type pos1 = use.find(L"ab"); + + VERIFY( pos1 == npos ); +} + +int main() +{ + test01(); + return 0; +}