From patchwork Thu Oct 31 12:34:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Smith-Rowland <3dw4rd@verizon.net> X-Patchwork-Id: 287477 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 809B12C037E for ; Thu, 31 Oct 2013 23:35:24 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=Llyu5mfGG3QAS/Mi6 ACTM8byHuu/13ZhKd3+tQ3COgwZjhXeEnPLKjkfl2QjPEPpmnL+0xtCt2vahob3M NsvYtl2OXk9FBRelPqOwAo0D/hCVXbqMAxqQrQrq6OpdwBQBTJIa1h0bOXdvLmsy 9GIoiX9NonPdtDO/QFge+Z8hh8= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=QGlpfBNIxnQ/dwHd6pq0dXD EZG4=; b=e9O5PeDdt+W/45/2UWmN0oXZ4wg+9vgTq6ylIVSPY9//DYuDuzRavbX VttsQ7IKiFEtv1loZvn2BIYWf8AwoDma84R0OXiW99Kb46R7ydPHQmRXgP2yAfsv Dz4G1qIThG5TEpbtOcrG02wVQ9saogzO0RXgwGIYHg89OwlRMrKM= Received: (qmail 28715 invoked by alias); 31 Oct 2013 12:35:17 -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 28689 invoked by uid 89); 31 Oct 2013 12:35:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: vms173005pub.verizon.net Received: from vms173005pub.verizon.net (HELO vms173005pub.verizon.net) (206.46.173.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 Oct 2013 12:35:11 +0000 Received: from [192.168.1.13] ([unknown] [74.103.25.251]) by vms173005.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0MVJ00HTY9M6NV40@vms173005.mailsrvcs.net> for gcc-patches@gcc.gnu.org; Thu, 31 Oct 2013 07:34:55 -0500 (CDT) Message-id: <52724E6F.7040408@verizon.net> Date: Thu, 31 Oct 2013 08:34:55 -0400 From: Ed Smith-Rowland <3dw4rd@verizon.net> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-version: 1.0 To: Jakub Jelinek Cc: Paolo Carlini , gcc-patches , Jason Merrill Subject: Re: PR C++/58708 - string literal operator templates broken References: <5260A01F.5010701@verizon.net> <526A4304.6020800@oracle.com> <526A584F.4050400@verizon.net> <526A5BF3.1040708@oracle.com> <526A7618.5030601@verizon.net> <526A79C5.8040501@oracle.com> <526A8055.6020907@verizon.net> <20131025144013.GI30970@tucnak.zalov.cz> In-reply-to: <20131025144013.GI30970@tucnak.zalov.cz> Content-type: multipart/mixed; boundary=------------010900030707030001070308 On 10/25/2013 10:40 AM, Jakub Jelinek wrote: > On Fri, Oct 25, 2013 at 10:29:41AM -0400, Ed Smith-Rowland wrote: >> 2013-10-25 Edward Smith-Rowland <3dw4rd@verizon.net> >> >> PR c++/58708 >> * parser.c (make_string_pack): Discover non-const type and size >> of character and build parm pack with correct type and chars. >> >> gcc/testsuite: >> >> 2013-10-25 Edward Smith-Rowland <3dw4rd@verizon.net> >> >> PR c++/58708 >> *g++.dg/cpp1y/pr58708.C : New. >> --- testsuite/g++.dg/cpp1y/pr58708.C (revision 0) >> +++ testsuite/g++.dg/cpp1y/pr58708.C (working copy) >> @@ -0,0 +1,91 @@ >> +// { dg-options -std=c++1y } >> +// { dg-do run } >> + >> +template >> + struct integral_constant >> + { >> + static constexpr _Tp value = __v; >> + typedef _Tp value_type; >> + typedef integral_constant<_Tp, __v> type; >> + constexpr operator value_type() const { return value; } >> + constexpr value_type operator()() const { return value; } >> + }; >> + >> +template >> + constexpr _Tp integral_constant<_Tp, __v>::value; >> + >> +typedef integral_constant true_type; >> + >> +typedef integral_constant false_type; >> + >> +template >> + struct is_same >> + : public false_type { }; >> + >> +template >> + struct is_same<_Tp, _Tp> >> + : public true_type { }; > Why not just the minimal: > template< class T, class U > > struct is_same { > static constexpr bool value = false; > }; > > template< class T > > struct is_same { > static constexpr bool value = true; > }; > other tests are using? > > Jakub > All, Here is a new patch. It's the same patch but a lighter testcase. Built and tested on x86_64-linux. OK? Ed gcc/cp: 2013-10-31 Edward Smith-Rowland <3dw4rd@verizon.net> PR c++/58708 * parser.c (make_string_pack): Discover non-const type and size of character and build parm pack with correct type and chars. gcc/testsuite: 2013-10-31 Edward Smith-Rowland <3dw4rd@verizon.net> PR c++/58708 *g++.dg/cpp1y/pr58708.C : New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 203997) +++ cp/parser.c (working copy) @@ -3793,22 +3793,39 @@ tree charvec; tree argpack = make_node (NONTYPE_ARGUMENT_PACK); const char *str = TREE_STRING_POINTER (value); - int i, len = TREE_STRING_LENGTH (value) - 1; + int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (value)))); + int len = TREE_STRING_LENGTH (value) / sz - 1; tree argvec = make_tree_vec (2); - tree string_char_type_node = TREE_TYPE (TREE_TYPE (value)); + tree str_char_type_node = TREE_TYPE (TREE_TYPE (value)); + str_char_type_node = TYPE_MAIN_VARIANT (str_char_type_node); /* First template parm is character type. */ - TREE_VEC_ELT (argvec, 0) = string_char_type_node; + TREE_VEC_ELT (argvec, 0) = str_char_type_node; /* Fill in CHARVEC with all of the parameters. */ charvec = make_tree_vec (len); - for (i = 0; i < len; ++i) - TREE_VEC_ELT (charvec, i) = build_int_cst (string_char_type_node, str[i]); + if (sz == 1) + { + for (int i = 0; i < len; ++i) + TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, str[i]); + } + else if (sz == 2) + { + const uint16_t *num = (const uint16_t *)str; + for (int i = 0; i < len; ++i) + TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, num[i]); + } + else if (sz == 4) + { + const uint32_t *num = (const uint32_t *)str; + for (int i = 0; i < len; ++i) + TREE_VEC_ELT (charvec, i) = build_int_cst (str_char_type_node, num[i]); + } /* Build the argument packs. */ SET_ARGUMENT_PACK_ARGS (argpack, charvec); - TREE_TYPE (argpack) = string_char_type_node; + TREE_TYPE (argpack) = str_char_type_node; TREE_VEC_ELT (argvec, 1) = argpack; Index: testsuite/g++.dg/cpp1y/pr58708.C =================================================================== --- testsuite/g++.dg/cpp1y/pr58708.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr58708.C (working copy) @@ -0,0 +1,60 @@ +// { dg-options -std=c++1y } +// { dg-do run } + +template + struct is_same + { + static constexpr bool value = false; + }; + +template + struct is_same<_Tp, _Tp> + { + static constexpr bool value = true; + }; + +template + struct Foo + { + using char_type = CharT; + char_type chars[sizeof...(Str)]{Str...}; + }; + +template + Foo + operator""_foo() + { + return Foo(); + } + +int +main() +{ + auto fooU = U"\x10000\x10001\x10002"_foo; + if (is_same::value != true) __builtin_abort(); + if (sizeof(fooU.chars)/sizeof(char32_t) != 3) __builtin_abort(); + if (fooU.chars[0] != 65536) __builtin_abort(); + if (fooU.chars[1] != 65537) __builtin_abort(); + if (fooU.chars[2] != 65538) __builtin_abort(); + + auto foo = "\x61\x62\x63"_foo; + if (is_same::value != true) __builtin_abort(); + if (sizeof(foo.chars)/sizeof(char) != 3) __builtin_abort(); + if (foo.chars[0] != 97) __builtin_abort(); + if (foo.chars[1] != 98) __builtin_abort(); + if (foo.chars[2] != 99) __builtin_abort(); + + auto wfoo = L"\x01020304\x05060708"_foo; + if (is_same::value != true) __builtin_abort(); + if (sizeof(wfoo.chars)/sizeof(wchar_t) != 2) __builtin_abort(); + if (wfoo.chars[0] != 16909060) __builtin_abort(); + if (wfoo.chars[1] != 84281096) __builtin_abort(); + + auto foou = u"\x0102\x0304\x0506\x0708"_foo; + if (is_same::value != true) __builtin_abort(); + if (sizeof(foou.chars)/sizeof(char16_t) != 4) __builtin_abort(); + if (foou.chars[0] != 258) __builtin_abort(); + if (foou.chars[1] != 772) __builtin_abort(); + if (foou.chars[2] != 1286) __builtin_abort(); + if (foou.chars[3] != 1800) __builtin_abort(); +}