From patchwork Tue Oct 9 13:07:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 981200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487203-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="McEgLyWS"; dkim-atps=neutral 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 42TyFM0Shpz9s5c for ; Wed, 10 Oct 2018 00:07:34 +1100 (AEDT) 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=BdAgTXwsCPMXM7+5UtGuD1Y7BCu3tE1j6HZBbEts+6pnZ3XpTVs+p Asr0BWLFZnuXQ5CR8DI1qwFsl2Xxz3Gi1VNEc5PTuGXniByEf5dPCB+njKtL2wkY NOFu5PRCcw9KFqgsxwrWjx8Aa+9lOSNCQ+7ieuJky39qBbY96ENl84= 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=CCA1ccyXibMMimWF/5RvkUzNG4Y=; b=McEgLyWSIOFW7r2/9SSu 2JyL2/osj1pIE8qv3UhWiM+pJs5twACOiLaLgNOWUL/zRNH2Y0eSPMT2vCnQA0sr yNUb6Ssg/U7YDHCuOK3Xq+VCPmhhKI+tzFNfdO5ipKajAKYnFmSsfumlN2ABhGXn vxnE/bifD9frv2KFi0l+o6Y= Received: (qmail 113831 invoked by alias); 9 Oct 2018 13:07:27 -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 113811 invoked by uid 89); 9 Oct 2018 13:07:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:basic_s 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; Tue, 09 Oct 2018 13:07:24 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA7B830DF6F1; Tue, 9 Oct 2018 13:07:23 +0000 (UTC) Received: from localhost (unknown [10.33.36.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 607B56A962; Tue, 9 Oct 2018 13:07:23 +0000 (UTC) Date: Tue, 9 Oct 2018 14:07:22 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Define std::string and related typedefs outside __cxx11 namespace Message-ID: <20181009130722.GA30303@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) The typedefs for common specializations of std::__cxx11::basic_string do not need to be in the std::__cxx11 namespace. Those typedefs are never used for linkage purposes so don't appear in mangled names, and so don't need to be distinct from the equivalent typedefs for the COW std::basic_string specializations. It is OK for the same typedef to refer to different types in different translation units. Defining them directly in namespace std improves diagnostics that use those typedefs. For example: error: could not convert '1' from 'int' to 'std::__cxx11::string' {aka 'std::__cxx11::basic_string'} will now be printed as: error: could not convert '1' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string'} The precise type is still shown, but the typedef is not obfuscated with the inline namespace. * include/bits/stringfwd.h (string, wstring, u16string, u32string): Define typedefs outside of __cxx11 inline namespace. * python/libstdcxx/v6/printers.py (register_type_printers): Also register printers for typedefs in new location. Tested x86_64-linux, committed to trunk. commit ee47efe7b3620fcfd3d65548e027523ca26a3615 Author: Jonathan Wakely Date: Tue Oct 9 12:19:29 2018 +0100 Define std::string and related typedefs outside __cxx11 namespace The typedefs for common specializations of std::__cxx11::basic_string do not need to be in the std::__cxx11 namespace. Those typedefs are never used for linkage purposes so don't appear in mangled names, and so don't need to be distinct from the equivalent typedefs for the COW std::basic_string specializations. It is OK for the same typedef to refer to different types in different translation units. Defining them directly in namespace std improves diagnostics that use those typedefs. For example: error: could not convert '1' from 'int' to 'std::__cxx11::string' {aka 'std::__cxx11::basic_string'} will now be printed as: error: could not convert '1' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string'} The precise type is still shown, but the typedef is not obfuscated with the inline namespace. * include/bits/stringfwd.h (string, wstring, u16string, u32string): Define typedefs outside of __cxx11 inline namespace. * python/libstdcxx/v6/printers.py (register_type_printers): Also register printers for typedefs in new location. diff --git a/libstdc++-v3/include/bits/stringfwd.h b/libstdc++-v3/include/bits/stringfwd.h index 15eb7183633..2b7f4612cbc 100644 --- a/libstdc++-v3/include/bits/stringfwd.h +++ b/libstdc++-v3/include/bits/stringfwd.h @@ -69,6 +69,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 typename _Alloc = allocator<_CharT> > class basic_string; +_GLIBCXX_END_NAMESPACE_CXX11 + /// A string of @c char typedef basic_string string; @@ -85,8 +87,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 typedef basic_string u32string; #endif -_GLIBCXX_END_NAMESPACE_CXX11 - /** @} */ _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index afe1b325d87..827c87b70ea 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1556,6 +1556,8 @@ def register_type_printers(obj): # Add type printers for typedefs std::string, std::wstring etc. for ch in ('', 'w', 'u16', 'u32'): add_one_type_printer(obj, 'basic_string', ch + 'string') + add_one_type_printer(obj, '__cxx11::basic_string', ch + 'string') + # Typedefs for __cxx11::basic_string used to be in namespace __cxx11: add_one_type_printer(obj, '__cxx11::basic_string', '__cxx11::' + ch + 'string') add_one_type_printer(obj, 'basic_string_view', ch + 'string_view') @@ -1568,7 +1570,7 @@ def register_type_printers(obj): for x in ('stringbuf', 'istringstream', 'ostringstream', 'stringstream'): add_one_type_printer(obj, 'basic_' + x, ch + x) - # types are in __cxx11 namespace, but typedefs aren'x: + # types are in __cxx11 namespace, but typedefs aren't: add_one_type_printer(obj, '__cxx11::basic_' + x, ch + x) # Add type printers for typedefs regex, wregex, cmatch, wcmatch etc.