From patchwork Mon Jun 12 22:28:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 774852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wmncT2rJXz9s06 for ; Tue, 13 Jun 2017 08:28:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mkBDV6bi"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=lnD7nAQoEfEkbKc7Vim/9NIGu/4aFZPVVg8XY22yK2Unzz3+fHTUg 6Di/F40X8Yo1OPcURg11hSVzw614nRJvZ2tzp/H7w76dFcMrENVqGy6JmPSijEUd 7jNka4kKCXa8MKU1AfHp+h/ZZ+CrZbF7gItqmoutIgNTy4H53s7aVE= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=default; bh=3zVjtBN2SW07VPn7LH3tkUF+ylg=; b=mkBDV6biq3leEHGZZRVyhklYnqxJ cM63x1UrTkwjS89jjiTxphvzBu+LIpJ+R42DJCL0TGgSN2tJ+0OhjhgDgeIDDHQG KFn5h22ZR/WFXJpTT0GJ4PFoCXjCZCWzJoerMYpnBtpYI1pi/B9k0fX4obaJf4yZ uYMZb3rRiUwDUkg= Received: (qmail 73901 invoked by alias); 12 Jun 2017 22:28:39 -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 67318 invoked by uid 89); 12 Jun 2017 22:28:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f171.google.com Received: from mail-wr0-f171.google.com (HELO mail-wr0-f171.google.com) (209.85.128.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 22:28:26 +0000 Received: by mail-wr0-f171.google.com with SMTP id q97so116586875wrb.2 for ; Mon, 12 Jun 2017 15:28:30 -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:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=B4yrWb0TLv/q05aBEEj+ScBcwUkT9MmcuazpXG9PWF0=; b=AJy4dfGo2aRxwQNAmgdW5TSWctOcO98YOHQp/kGOzF1fMgi+nuzt8Bofc3COdVetOu spicGJjStUXIlDNpU2/j+v4LWD8wgZqatzYImpQkLhHXeByNNdCA2FanQ1wKex5nhM9p 6pVDQyE8ogDQUGclvcU1kbGrf4CwFkxUjd/MJGcGfacjiGwVfWMJB96Qr9DfZd3OBVeF 4uta/HnVltGHUn8Pl8bzX86XapjbeGyfeUnPjQzjeCcehvaAJIfj9HEH3urKli56dAIj La8lnGvvcF3DVRnRYAyfB111pTJdRVrStzXszAWsNObJMeV9n0yxk0fNTqRZHzyE20Jt L3jg== X-Gm-Message-State: AKS2vOxo7+yywDwV7S6EAHqtBhuILkKiWA46lcdtbw/ocQKrdGZwz8lY gsky2kbAjf225wKkkEwF+Q== X-Received: by 10.28.184.216 with SMTP id i207mr9284096wmf.31.1497306508239; Mon, 12 Jun 2017 15:28:28 -0700 (PDT) Received: from [192.168.0.102] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id f70sm12128184wmd.25.2017.06.12.15.28.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:28:27 -0700 (PDT) Subject: Re: [PATCH] Finish implementing P0426R1 "Constexpr for std::char_traits" for C++17 To: Jonathan Wakely References: <0867f2ad-1381-fdda-2f03-2fdbd450faed@redhat.com> <20170605142734.GO12306@redhat.com> Cc: libstdc++@gcc.gnu.org, "gcc-patches@gcc.gnu.org" From: Pedro Alves Message-ID: <38d6cdc6-554a-6d0d-e76d-c7d340bf1e75@redhat.com> Date: Mon, 12 Jun 2017 23:28:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170605142734.GO12306@redhat.com> On 06/05/2017 03:27 PM, Jonathan Wakely wrote: > Pedro, this is OK for trunk now we're in stage 1. Please go ahead and > commit it - thanks. Thanks Jonathan. I've pushed it in now. > > It's probably safe for gcc-7-branch too, but let's leave it on trunk > for a while first. OK. BTW, for extra thoroughness, to confirm we're handling both const & non-const arrays correctly, I had written this testsuite tweak too. Would you like to have this in? From 3f7adab8bab68955aafd760467bb860057140d40 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 12 Jun 2017 20:23:23 +0100 Subject: [PATCH] constexpr char_traits: Test non-const strings/arrays too libstdc++-v3/ChangeLog yyyy-mm-dd Pedro Alves * testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc (test_assign, test_compare, test_length, test_find): Test non-const strings/arrays too. (struct C): Add a generic conversion ctor. --- .../requirements/constexpr_functions_c++17.cc | 173 ++++++++++++++++++--- 1 file changed, 150 insertions(+), 23 deletions(-) diff --git a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc index efd280f..c41b490 100644 --- a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc +++ b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc @@ -25,10 +25,40 @@ template test_assign() { using char_type = typename CT::char_type; - char_type s1[2] = {}; - const char_type s2[2] = {1, 0}; - CT::assign(s1[0], s2[0]); - return s1[0] == char_type{1}; + + auto check = [](char_type* s1, const char_type* s2) + { + CT::assign(s1[0], s2[0]); + return s1[0] == char_type{1}; + }; + + // const strings. + + { + char_type s1[2] = {}; + const char_type s2[2] = {1, 0}; + if (!check (s1, s2)) + return false; + } + + // non-const strings. + + { + char_type s1[2] = {}; + char_type s2[2] = {1, 0}; + if (!check (s1, s2)) + return false; + } + + { + char_type s1[2] = {}; + char_type s2[2] = {}; + s2[0] = char_type{1}; + if (!check (s1, s2)) + return false; + } + + return true; } template @@ -36,14 +66,48 @@ template test_compare() { using char_type = typename CT::char_type; - const char_type s1[3] = {1, 2, 3}; - const char_type s2[3] = {1, 2, 3}; - if (CT::compare(s1, s2, 3) != 0) - return false; - if (CT::compare(s2, s1, 3) != 0) - return false; - if (CT::compare(s1+1, s2, 2) <= 0) - return false; + + auto check = [](const char_type* s1, const char_type* s2) + { + if (CT::compare(s1, s2, 3) != 0) + return false; + if (CT::compare(s2, s1, 3) != 0) + return false; + if (CT::compare(s1+1, s2, 2) <= 0) + return false; + return true; + }; + + // const arrays. + + { + const char_type s1[3] = {1, 2, 3}; + const char_type s2[3] = {1, 2, 3}; + if (!check (s1, s2)) + return false; + } + + // non-const arrays. + + { + char_type s1[3] = {1, 2, 3}; + char_type s2[3] = {1, 2, 3}; + if (!check (s1, s2)) + return false; + } + + { + char_type s1[3] = {}; + char_type s2[3] = {}; + for (size_t i = 0; i < 3; i++) + { + s1[i] = char_type(i+1); + s2[i] = char_type(i+1); + } + if (!check (s1, s2)) + return false; + } + return true; } @@ -52,11 +116,40 @@ template test_length() { using char_type = typename CT::char_type; - const char_type s1[4] = {1, 2, 3, 0}; - if (CT::length(s1) != 3) - return false; - if (CT::length(s1+1) != 2) - return false; + + auto check = [](const char_type* s) + { + if (CT::length(s) != 3) + return false; + if (CT::length(s+1) != 2) + return false; + return true; + }; + + // const strings. + + { + const char_type s[4] = {1, 2, 3, 0}; + if (!check (s)) + return false; + } + + // non-const strings. + + { + char_type s[4] = {1, 2, 3, 0}; + if (!check (s)) + return false; + } + + { + char_type s[4] = {}; + for (size_t i = 0; i < 3; i++) + s[i] = char_type(i+1); + if (!check (s)) + return false; + } + return true; } @@ -65,11 +158,40 @@ template test_find() { using char_type = typename CT::char_type; - const char_type s1[3] = {1, 2, 3}; - if (CT::find(s1, 3, char_type{2}) != s1+1) - return false; - if (CT::find(s1, 3, char_type{4}) != nullptr) - return false; + + auto check = [](const char_type* s) + { + if (CT::find(s, 3, char_type{2}) != s+1) + return false; + if (CT::find(s, 3, char_type{4}) != nullptr) + return false; + return true; + }; + + // const arrays. + + { + const char_type s[3] = {1, 2, 3}; + if (!check(s)) + return false; + } + + // non-const arrays. + + { + char_type s[3] = {1, 2, 3}; + if (!check(s)) + return false; + } + + { + char_type s[3] = {}; + for (size_t i = 0; i < 3; i++) + s[i] = char_type(i+1); + if (!check(s)) + return false; + } + return true; } @@ -98,7 +220,12 @@ static_assert( test_compare>() ); static_assert( test_length>() ); static_assert( test_find>() ); -struct C { unsigned char c; }; +struct C +{ + C() = default; + constexpr C(auto c_) : c(c_) {} + unsigned char c; +}; constexpr bool operator==(const C& c1, const C& c2) { return c1.c == c2.c; } constexpr bool operator<(const C& c1, const C& c2) { return c1.c < c2.c; } static_assert( test_assign>() );