diff mbox series

Define std::string and related typedefs outside __cxx11 namespace

Message ID 20181009130722.GA30303@redhat.com
State New
Headers show
Series Define std::string and related typedefs outside __cxx11 namespace | expand

Commit Message

Jonathan Wakely Oct. 9, 2018, 1:07 p.m. UTC
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<char>'}

will now be printed as:

error: could not convert '1' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}

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 <jwakely@redhat.com>
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<char>'}
    
    will now be printed as:
    
    error: could not convert '1' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
    
    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 mbox series

Patch

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<char>    string;   
 
@@ -85,8 +87,6 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
   typedef basic_string<char32_t> 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)
-            # <sstream> types are in __cxx11 namespace, but typedefs aren'x:
+            # <sstream> 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.