From patchwork Thu May 15 12:30:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 349198 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 9510B140086 for ; Thu, 15 May 2014 22:31:09 +1000 (EST) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=RefPjys3Au6pcJp9mpiDgdONTw3OFzc10W6Yo819QS54G1F3YFrky //oCajnWpgI0V8/P0rd0gFCuDJlnARbH+e0tk7oZGLsD8DwGnlra4Xsh2DPcpe5f h56CiB/ERxoFEexvM+CcDI/6BVhr5M62duhts0JMFYsXBEcKNuIvxI= 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:subject:message-id:mime-version:content-type; s= default; bh=DrOqdKS6JjWEwfxeV0emFwJo37s=; b=ZlYv6ED1z8hlmtIBqqNX 3zP/XHWJqYCctzoO1LAEhO7YK503uiArujtshaZpswUtFnjIiS/z58wgpUAc2nxZ V0qb2z7D3hlogtBw3kvh9BdncznhG58lxyI7+UYL0oKw4knl2M0/I/fc5HwWBtAz exhNanEthsHZrHcAk/K/+oc= Received: (qmail 14018 invoked by alias); 15 May 2014 12:31:02 -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 13993 invoked by uid 89); 15 May 2014 12:31:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 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; Thu, 15 May 2014 12:31:00 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4FCUwxe014876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 May 2014 08:30:58 -0400 Received: from localhost (vpn1-6-198.ams2.redhat.com [10.36.6.198]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4FCUveO010508; Thu, 15 May 2014 08:30:58 -0400 Date: Thu, 15 May 2014 13:30:57 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] libstdc++/60326 make_signed/make_unsigned for wide char types Message-ID: <20140515123057.GA26271@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) We are missing specializations for wchar_t, char16_t and char32_t. The preprocessor condition I've added at the top of is to avoid needing to #include , which drops names in the global namespace. GCC defines __UINT_LEAST16_TYPE__ and __UINT_LEAST32_TYPE__ so we can use them, but other compilers may not (Clang doesn't) so just #include and accept that might put its contents in the global namespace. Tested x86_64-linux, committed to trunk. I'd like to put this on the branch for 4.9.1 too, but will wait a while. commit e1804a737ee8f12f2e1e4fb93693eb96bff6e8af Author: Jonathan Wakely Date: Tue May 13 16:04:37 2014 +0100 PR libstdc++/60326 * include/std/type_traits (__make_unsigned, __make_signed): Define specializations for wchar_t, char16_t and char32_t. * testsuite/20_util/make_signed/requirements/typedefs-4.cc: New. * testsuite/20_util/make_unsigned/requirements/typedefs-1.cc: Correct test for make_unsigned. * testsuite/20_util/make_unsigned/requirements/typedefs-2.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error line number. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4b434a6..0eacd36 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -41,6 +41,15 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 +# if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__) + typedef __UINT_LEAST16_TYPE__ uint_least16_t; + typedef __UINT_LEAST32_TYPE__ uint_least32_t; +# else +# include +# endif +#endif + /** * @defgroup metaprogramming Metaprogramming * @ingroup utilities @@ -1583,6 +1592,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __make_unsigned { typedef unsigned long long __type; }; +#if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__) + template<> + struct __make_unsigned : __make_unsigned<__WCHAR_TYPE__> + { }; +#endif + #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) template<> struct __make_unsigned<__int128> @@ -1665,6 +1680,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __make_signed { typedef signed long long __type; }; +#if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__) + template<> + struct __make_signed : __make_signed<__WCHAR_TYPE__> + { }; +#endif + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + template<> + struct __make_signed : __make_signed + { }; + template<> + struct __make_signed : __make_signed + { }; +#endif + #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) template<> struct __make_signed diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index a744d83..6be3af0 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 2003 } +// { dg-error "static assertion failed" "" { target *-*-* } 2033 } #include diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-4.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-4.cc new file mode 100644 index 0000000..4950e54 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-4.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } +// { dg-require-cstdint "" } + +// Copyright (C) 2014 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 +// . + +#include + +// libstdc++/60326 + +using namespace std; +#ifdef _GLIBCXX_USE_WCHAR_T +using wchar_signed = make_signed::type; +using wchar_unsigned = make_unsigned::type; +static_assert( !is_same::value, "wchar_t" ); +#endif +static_assert( is_signed::type>::value, "char16_t"); +static_assert( is_signed::type>::value, "char32_t"); diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index 9f155ea..77f8bb3 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -48,5 +48,5 @@ void test01() // { dg-error "required from here" "" { target *-*-* } 40 } // { dg-error "required from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1714 } -// { dg-error "declaration of" "" { target *-*-* } 1678 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1744 } +// { dg-error "declaration of" "" { target *-*-* } 1708 } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc index f07cf4a..a893ede 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc @@ -49,7 +49,7 @@ void test01() #ifdef _GLIBCXX_USE_WCHAR_T typedef make_unsigned::type test23_type; - static_assert(is_same::value, ""); + static_assert(is_same::value, ""); #endif // Chapter 48, chapter 20. Smallest rank such that new unsigned type diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc index 8997fb7..637b0c7 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc @@ -50,7 +50,7 @@ void test01() #ifdef _GLIBCXX_USE_WCHAR_T typedef make_unsigned::type test23_type; - static_assert(is_same::value, ""); + static_assert(is_same::value, ""); #endif typedef make_unsigned::type test24_type; diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index 57a5c61..48ee225 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -48,5 +48,5 @@ void test01() // { dg-error "required from here" "" { target *-*-* } 40 } // { dg-error "required from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1632 } -// { dg-error "declaration of" "" { target *-*-* } 1596 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1647 } +// { dg-error "declaration of" "" { target *-*-* } 1611 }