public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matthias Kretz <m.kretz@gsi.de>
To: <gcc-patches@gcc.gnu.org>, <libstdc++@gcc.gnu.org>
Subject: [PATCH 1/2] libstdc++: Use diagnose_as attribute to improve string diagnostics
Date: Mon, 15 Nov 2021 18:05:20 +0100	[thread overview]
Message-ID: <1919124.eP8hAHRRDn@excalibur> (raw)
In-Reply-To: <1849892.9kXth2LyAg@excalibur>

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]



This hides the basic_string template in all diagnostics, reducing the
signal-to-noise ratio significantly. It also hides the std::__cxx11
namespace from users by presenting it as std.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

	PR c++/89370
	* include/bits/c++config: Diagnose std::__cxx11:: as std:: using
	the diagnose_as attribute.
	* include/bits/stringfwd.h: Add diagnose_as attribute to string,
	wstring, u8string, u16string, and u32string.
	* include/debug/string: Ditto.
	* include/experimental/string: Ditto.
	* include/std/string: Ditto.
---
 libstdc++-v3/include/bits/c++config      |  3 ++-
 libstdc++-v3/include/bits/stringfwd.h    | 10 +++++-----
 libstdc++-v3/include/debug/string        | 10 +++++-----
 libstdc++-v3/include/experimental/string | 10 +++++-----
 libstdc++-v3/include/std/string          | 10 +++++-----
 5 files changed, 22 insertions(+), 21 deletions(-)


--
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 stdₓ::simd
──────────────────────────────────────────────────────────────────────────

[-- Attachment #2: 0001-libstdc-Use-diagnose_as-attribute-to-improve-string-.patch --]
[-- Type: text/x-patch, Size: 4940 bytes --]

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index a6495809671..02d11afc1aa 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -318,7 +318,8 @@ namespace std
 #if _GLIBCXX_USE_CXX11_ABI
 namespace std
 {
-  inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
+  inline namespace __cxx11
+    __attribute__((__abi_tag__ ("cxx11"), __diagnose_as__("std"))) { }
 }
 namespace __gnu_cxx
 {
diff --git a/libstdc++-v3/include/bits/stringfwd.h b/libstdc++-v3/include/bits/stringfwd.h
index bcfd350e505..3f653feae14 100644
--- a/libstdc++-v3/include/bits/stringfwd.h
+++ b/libstdc++-v3/include/bits/stringfwd.h
@@ -74,22 +74,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 _GLIBCXX_END_NAMESPACE_CXX11
 
   /// A string of @c char
-  typedef basic_string<char>    string;   
+  typedef basic_string<char>    string __attribute__((__diagnose_as__));
 
   /// A string of @c wchar_t
-  typedef basic_string<wchar_t> wstring;   
+  typedef basic_string<wchar_t> wstring __attribute__((__diagnose_as__));
 
 #ifdef _GLIBCXX_USE_CHAR8_T
   /// A string of @c char8_t
-  typedef basic_string<char8_t> u8string;
+  typedef basic_string<char8_t> u8string __attribute__((__diagnose_as__));
 #endif
 
 #if __cplusplus >= 201103L
   /// A string of @c char16_t
-  typedef basic_string<char16_t> u16string; 
+  typedef basic_string<char16_t> u16string __attribute__((__diagnose_as__));
 
   /// A string of @c char32_t
-  typedef basic_string<char32_t> u32string; 
+  typedef basic_string<char32_t> u32string __attribute__((__diagnose_as__));
 #endif
 
   /** @}  */
diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index a8389528001..d6299e5552f 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -1296,21 +1296,21 @@ namespace __gnu_debug
       return __res;
     }
 
-  typedef basic_string<char>    string;
+  typedef basic_string<char>    string __attribute__((__diagnose_as__));
 
-  typedef basic_string<wchar_t> wstring;
+  typedef basic_string<wchar_t> wstring __attribute__((__diagnose_as__));
 
 #ifdef _GLIBCXX_USE_CHAR8_T
   /// A string of @c char8_t
-  typedef basic_string<char8_t> u8string;
+  typedef basic_string<char8_t> u8string __attribute__((__diagnose_as__));
 #endif
 
 #if __cplusplus >= 201103L
   /// A string of @c char16_t
-  typedef basic_string<char16_t> u16string;
+  typedef basic_string<char16_t> u16string __attribute__((__diagnose_as__));
 
   /// A string of @c char32_t
-  typedef basic_string<char32_t> u32string;
+  typedef basic_string<char32_t> u32string __attribute__((__diagnose_as__));
 #endif
 
   template<typename _CharT, typename _Traits, typename _Allocator>
diff --git a/libstdc++-v3/include/experimental/string b/libstdc++-v3/include/experimental/string
index 4d92a7e39cc..91a9dd8b164 100644
--- a/libstdc++-v3/include/experimental/string
+++ b/libstdc++-v3/include/experimental/string
@@ -73,13 +73,13 @@ inline namespace fundamentals_v2
 
     // basic_string typedef names using polymorphic allocator in namespace
     // std::experimental::pmr
-    typedef basic_string<char> string;
+    typedef basic_string<char> string __attribute__((__diagnose_as__));
 #ifdef _GLIBCXX_USE_CHAR8_T
-    typedef basic_string<char8_t> u8string;
+    typedef basic_string<char8_t> u8string __attribute__((__diagnose_as__));
 #endif
-    typedef basic_string<char16_t> u16string;
-    typedef basic_string<char32_t> u32string;
-    typedef basic_string<wchar_t> wstring;
+    typedef basic_string<char16_t> u16string __attribute__((__diagnose_as__));
+    typedef basic_string<char32_t> u32string __attribute__((__diagnose_as__));
+    typedef basic_string<wchar_t> wstring __attribute__((__diagnose_as__));
 
   } // namespace pmr
 #endif
diff --git a/libstdc++-v3/include/std/string b/libstdc++-v3/include/std/string
index af840e887d5..03a3c68050f 100644
--- a/libstdc++-v3/include/std/string
+++ b/libstdc++-v3/include/std/string
@@ -62,13 +62,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     template<typename _CharT, typename _Traits = char_traits<_CharT>>
       using basic_string = std::basic_string<_CharT, _Traits,
 					     polymorphic_allocator<_CharT>>;
-    using string    = basic_string<char>;
+    using string    [[__gnu__::__diagnose_as__]] = basic_string<char>;
 #ifdef _GLIBCXX_USE_CHAR8_T
-    using u8string  = basic_string<char8_t>;
+    using u8string  [[__gnu__::__diagnose_as__]] = basic_string<char8_t>;
 #endif
-    using u16string = basic_string<char16_t>;
-    using u32string = basic_string<char32_t>;
-    using wstring   = basic_string<wchar_t>;
+    using u16string [[__gnu__::__diagnose_as__]] = basic_string<char16_t>;
+    using u32string [[__gnu__::__diagnose_as__]] = basic_string<char32_t>;
+    using wstring   [[__gnu__::__diagnose_as__]] = basic_string<wchar_t>;
   } // namespace pmr
 
   template<typename _Str>

  reply	other threads:[~2021-11-15 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 17:04 [PATCH 0/2] Make use of the diagnose_as attribute to improve libstdc++ diagnostics Matthias Kretz
2021-11-15 17:05 ` Matthias Kretz [this message]
2021-11-15 17:05 ` [PATCH 2/2] libstdc++: Use diagnose_as attribute to improve simd diagnostics Matthias Kretz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1919124.eP8hAHRRDn@excalibur \
    --to=m.kretz@gsi.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).