Re: [ PATCH ] [ C++ ] Implementing P0767 - deprecate POD

2019-12-04 Thread JeanHeyd Meneide
Dear Jonathan,

Done! re-patched, below.

Best,
JeanHeyd

2019-12-03  JeanHeyd "ThePhD" Meneide  

* include/bits/c++config: Add new _GLIBCXX20_DEPRECATED macro.
* include/std/type_traits: Deprecate is_pod with message.
* testuite/20_util/is_pod/deprecated-2a.cc (new): test deprecation
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 7ccfc5f199d..9e85fc2c9e8 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -78,6 +78,7 @@
 //   _GLIBCXX_USE_DEPRECATED
 //   _GLIBCXX_DEPRECATED
 //   _GLIBCXX17_DEPRECATED
+//   _GLIBCXX20_DEPRECATED( STRINGS... )
 #ifndef _GLIBCXX_USE_DEPRECATED
 # define _GLIBCXX_USE_DEPRECATED 1
 #endif
@@ -94,6 +95,12 @@
 # define _GLIBCXX17_DEPRECATED
 #endif
 
+#if defined(__DEPRECATED) && (__cplusplus > 201703L)
+# define _GLIBCXX20_DEPRECATED(MSG) [[deprecated(MSG)]]
+#else
+# define _GLIBCXX20_DEPRECATED(MSG) 
+#endif
+
 // Macros for ABI tag attributes.
 #ifndef _GLIBCXX_ABI_TAG_CXX11
 # define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 8e787a994c3..5980b21c763 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -685,10 +685,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
"template argument must be a complete class or an unbounded array");
 };
 
-  /// is_pod
+  /// is_pod (deprecated C++2a)
   // Could use is_standard_layout && is_trivial instead of the builtin.
   template
-struct is_pod
+struct
+_GLIBCXX20_DEPRECATED("is_pod is deprecated in C++20: use 
(is_standard_layout_v && is_trivial_v) instead") 
+is_pod
 : public integral_constant
 {
   static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
@@ -3073,6 +3075,7 @@ template 
 template 
   inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
 template 
+  _GLIBCXX20_DEPRECATED("is_pod_v is deprecated in C++20: use 
(is_standard_layout_v && is_trivial_v) instead")
   inline constexpr bool is_pod_v = is_pod<_Tp>::value;
 template 
   inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
diff --git a/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc 
b/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc
new file mode 100644
index 000..1035a729434
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2019 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
+// .
+
+// { dg-do compile { target c++2a } }
+
+// { dg-prune-output "declared here" }
+
+#include 
+
+static_assert(std::is_pod::value); // { dg-warning "is deprecated" }
+static_assert(std::is_pod_v); // { dg-warning "is deprecated" }


[ PATCH ] [ C++ ] [ libstdc++ ] P1208r6 Merge source_location

2019-12-27 Thread JeanHeyd Meneide
 This patch implements std::source_location. There's a couple
cases where the builtin implemented does not do what is expected of
it, and so the bottom 3 batches of test cases fails. I'm still
including the patch so that others can pick up on what might need to
change about the __builtin_source_location implementation (CC:
Jonathan Wakely, Jakub Jelinek).

2019-12-27  JeanHeyd "ThePhD" Meneide  

* include/Makefile.in: add source_location header
* include/bits/c++config: Add new detection macros for
  LINE, COLUMN, and SOURCE_LOCATION builtins.
* include/std/source_location: New.
* testuite/std/support/srcloc/std.n4842.C (new): test source_location
* testuite/std/support/srcloc/std.n4842.h (new): test source_location
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 6300de9e96d..fc593c7c461 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -70,6 +70,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index ae4a493ea65..c104ffb28ab 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -414,6 +414,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 7ccfc5f199d..2d2ec96a925 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -630,6 +630,7 @@ namespace std
 
 #if __GNUC__ >= 7
 // Assume these are available if the compiler claims to be a recent GCC:
+# define _GLIBCXX_HAVE_BUILTIN_LINE 1
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
@@ -637,6 +638,9 @@ namespace std
 # if __GNUC__ >= 9
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
+# if __GNUC__ >= 10
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
 #elif defined(__is_identifier) && defined(__has_builtin)
 // For non-GNU compilers:
 # if ! __is_identifier(__has_unique_object_representations)
@@ -654,6 +658,15 @@ namespace std
 # if ! __is_identifier(__is_same)
 #  define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same(T, U)
 # endif
+# if __has_builtin(__builtin_source_location)
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
+# if __has_builtin(__builtin_LINE)
+#  define _GLIBCXX_HAVE_BUILTIN_LINE 1
+# endif
+# if __has_builtin(__builtin_COLUMN)
+#  define _GLIBCXX_HAVE_BUILTIN_COLUMN 1
+# endif
 #endif // GCC
 
 // PSTL configuration
diff --git a/libstdc++-v3/include/std/source_location 
b/libstdc++-v3/include/std/source_location
new file mode 100644
index 000..3bf219efa81
--- /dev/null
+++ b/libstdc++-v3/include/std/source_location
@@ -0,0 +1,172 @@
+// Component for retrieving function, line and column source info. -*- C++ -*-
+
+// Copyright (C) 2019 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// .
+
+/** @file source_location
+ *  This is a Standard C++ Library header.
+ */
+
+//
+// P1208 source_location library
+// Contributed by ThePhD with <3
+//
+
+#ifndef _GLIBCXX_SOURCE_LOCATION
+#define _GLIBCXX_SOURCE_LOCATION 1
+
+#pragma GCC system_header
+
+#if __cplusplus > 201703L
+
+#include 
+#include 
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+#define __cpp_lib_source_location 201907L
+
+// use by-pointer for GCC-style __builtin_source_location;
+// use by-value for Clang-style builtins.
+#ifdef _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION
+

Re: [ PATCH ] [ C++ ] [ libstdc++ ] P1208r6 Merge source_location

2019-12-27 Thread JeanHeyd Meneide
On Fri, Dec 27, 2019 at 2:33 PM Jakub Jelinek  wrote:
>
> This will be ABI incompatible between GCC and Clang, that doesn't look like
> a good idea to me.  I thought the plan is to use what you have in the
> _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION case always, except that if
> __builtin_source_location isn't available, initialize _M_data to nullptr.

You're right, it's probably bad to have an implementation that
switches. I guess that means clang folks will have to implement the
builtin too at some point (but Jonathan's comment in the
__builtin_source_location patch said they might not, so I'm not sure
what to do for Clang here I guess?).

To more clearly explain the test failures and the static_assert
failures, there are cases where -- when the default argument can be
manifestly constant evaluated -- it does not report the a function
name or anything at all. It also uses the line of where the Nonstatic
Data Member Initializer is for initialization of class members, rather
than the line of the constructor where the initialization happens.
These are things that the Standard's examples say *should* work, but I
don't know how normative Examples are in the standard that use
comments to explain things:
http://eel.is/c++draft/support.srcloc#cons-4

Best Wishes,
JeanHeyd
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 6300de9e96d..fc593c7c461 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -70,6 +70,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index ae4a493ea65..c104ffb28ab 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -414,6 +414,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 7ccfc5f199d..2d2ec96a925 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -630,6 +630,7 @@ namespace std
 
 #if __GNUC__ >= 7
 // Assume these are available if the compiler claims to be a recent GCC:
+# define _GLIBCXX_HAVE_BUILTIN_LINE 1
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
@@ -637,6 +638,9 @@ namespace std
 # if __GNUC__ >= 9
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
+# if __GNUC__ >= 10
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
 #elif defined(__is_identifier) && defined(__has_builtin)
 // For non-GNU compilers:
 # if ! __is_identifier(__has_unique_object_representations)
@@ -654,6 +658,15 @@ namespace std
 # if ! __is_identifier(__is_same)
 #  define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same(T, U)
 # endif
+# if __has_builtin(__builtin_source_location)
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
+# if __has_builtin(__builtin_LINE)
+#  define _GLIBCXX_HAVE_BUILTIN_LINE 1
+# endif
+# if __has_builtin(__builtin_COLUMN)
+#  define _GLIBCXX_HAVE_BUILTIN_COLUMN 1
+# endif
 #endif // GCC
 
 // PSTL configuration
diff --git a/libstdc++-v3/include/std/source_location 
b/libstdc++-v3/include/std/source_location
new file mode 100644
index 000..e2727ebd196
--- /dev/null
+++ b/libstdc++-v3/include/std/source_location
@@ -0,0 +1,103 @@
+// Component for retrieving function, line and column source info. -*- C++ -*-
+
+// Copyright (C) 2019 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// .
+
+/** @file source_location
+ *  This is a Standard C++ Library header.
+ */
+
+//
+/

Re: [ PATCH ] [ C++ ] [ libstdc++ ] P1208r6 Merge source_location

2020-01-02 Thread JeanHeyd Meneide
On Thu, Jan 2, 2020 at 5:28 AM Jonathan Wakely  wrote:
>
> Do nothing - compiling with Clang won't define std::source_location at
> all.

You got it! Patch re-done after discussion here
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093) and recommended
no-Clang change.

2020-01-02  JeanHeyd "ThePhD" Meneide  

* include/Makefile.in: add source_location header
* include/bits/c++config: Add new detection macros for
  LINE, COLUMN, and SOURCE_LOCATION builtins.
* include/std/source_location: New.
* testuite/std/support/srcloc/consteval.std.n4842.h (new):
test source_location
* testuite/std/support/srcloc/std.n4842.C (new): test source_location
* testuite/std/support/srcloc/std.n4842.h (new): test source_location
diff --git a/libstdc++-v3/include/Makefile.in 
b/libstdc++-v3/include/Makefile.in
index ae4a493ea65..c104ffb28ab 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -414,6 +414,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index f983743b052..6ca431b24ee 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -630,6 +630,7 @@ namespace std
 
 #if __GNUC__ >= 7
 // Assume these are available if the compiler claims to be a recent GCC:
+# define _GLIBCXX_HAVE_BUILTIN_LINE 1
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
@@ -637,6 +638,9 @@ namespace std
 # if __GNUC__ >= 9
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
+# if __GNUC__ >= 10
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
 #elif defined(__is_identifier) && defined(__has_builtin)
 // For non-GNU compilers:
 # if ! __is_identifier(__has_unique_object_representations)
@@ -654,6 +658,15 @@ namespace std
 # if ! __is_identifier(__is_same)
 #  define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same(T, U)
 # endif
+# if __has_builtin(__builtin_source_location)
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
+# if __has_builtin(__builtin_LINE)
+#  define _GLIBCXX_HAVE_BUILTIN_LINE 1
+# endif
+# if __has_builtin(__builtin_COLUMN)
+#  define _GLIBCXX_HAVE_BUILTIN_COLUMN 1
+# endif
 #endif // GCC
 
 // PSTL configuration
diff --git a/libstdc++-v3/include/std/source_location 
b/libstdc++-v3/include/std/source_location
new file mode 100644
index 000..4c805df0dfa
--- /dev/null
+++ b/libstdc++-v3/include/std/source_location
@@ -0,0 +1,101 @@
+// Component for retrieving function, line and column source info. -*- C++ -*-
+
+// Copyright (C) 2019-2020 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// .
+
+/** @file source_location
+ *  This is a Standard C++ Library header.
+ */
+
+//
+// P1208 source_location library
+// Contributed by ThePhD with <3
+//
+
+#ifndef _GLIBCXX_SOURCE_LOCATION
+#define _GLIBCXX_SOURCE_LOCATION 1
+
+#pragma GCC system_header
+
+#include 
+#include 
+
+#if __cplusplus > 201703L
+#ifdef _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+#define __cpp_lib_source_location 201907L
+
+  struct source_location
+  {
+  private:
+struct __impl
+{
+  const char *_M_file_name;
+  const char *_M_function_name;
+  unsigned int _M_line, _M_column;
+};
+
+  public:
+static consteval source_location
+current (const void *__src_loc_impl = __builtin_source_location ()) 
noexcept
+{
+  source_location __ret;
+  __ret._M_data = static_cast(__src_loc_impl);
+  return __ret;
+}
+
+constexpr
+source_location () noexcept
+: _M_data ()
+{ }
+
+constexpr const char *
+file_name () cons

[ PATCH ] [ C++ ] [ libstdc++ ] P0674r1 - Extend support for arrays in make/allocate_shared

2020-01-02 Thread JeanHeyd Meneide
Glen Fernandes is already working on a patch, so I decided to finish
off my changes and throw them up on the Patch List so that Glen can
access the tests parts that I had written (they are not incredibly
extensive but do pass).

For a small implementation description: the code I use does the
same in-place, fused-allocation technique used by other internal
classes of shared_ptr, and also creates some helpers in a new
bits/multi_dim.h header to simplify accessing multiple dimensions in a
proper order (useful for destruction, but construction is easy
enough). This might also come in handy down the road when mdspan
(finally) gets standardized.

 This implementation does not update the internal
__allocate_shared and __make_shared functions (I don't know why there
seems to be a duplicate front-end for those functions: it seems a
little weird to use both? Maybe it's for legacy reasons, albeit if
that is the case then I don't need to update the internal versions and
people should move to the non-internal version, yes?).

2020-01-02  JeanHeyd "ThePhD" Meneide  

* include/bits/multi_dim.h (new): New helpers for multi
  dimensional access.
* include/bits/alloc_traits.h: New helpers for multi dimensional
  array construction and destruction.
* include/bits/allocated_ptr.h: New guard type for sized
  allocation.
* include/bits/memoryfwd.h: std::align forward declaration.
* include/bits/shared_ptr.h: Changes to support multi
  dimensional array access with optimized size/extent storage.
* include/bits/stl_construct.h: Formatting.
* testsuite/20_util/shared_ptr/creation.array_support.allocate.cc:
  New test.
* testsuite/20_util/shared_ptr/creation.array_support.make.cc:
  New test.
diff --git a/libstdc++-v3/include/bits/alloc_traits.h 
b/libstdc++-v3/include/bits/alloc_traits.h
index 061d353e3f0..39dcb639143 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -37,6 +37,9 @@
 # include 
 # include 
 #endif
+#if __cplusplus > 201703L
+#include 
+#endif // C++20 and above multi dimensional tools
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -703,6 +706,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 using _RequireNotAllocator
   = typename enable_if::value, _Alloc>::type;
+
+  template 
+using __alloc_size
+  = typename allocator_traits<_Alloc>::size_type;
 #endif // C++11
 
   /**
@@ -733,6 +740,189 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _Destroy(__first, __last);
 }
 
+
+
+#if __cplusplus > 201703L
+  /// Helpers for getting multi-dimensional construction an destruction
+  /// done properly. Obeys C++ Standard rules for array acccess: works
+  /// in constexpr.
+
+  template
+constexpr void
+__recursive_element_construct_1 (_ElemAlloc& __elem_alloc,
+_Ty* __ptr,
+__alloc_size<_ElemAlloc>& __constructed,
+__alloc_size<_ElemAlloc> __extent,
+const _Init& __value)
+{
+  using _SizeType = __alloc_size<_ElemAlloc>;
+  if constexpr (rank_v<_Ty> == 0)
+   {
+ for (_SizeType __idx = 0; __idx < __extent; ++__idx)
+   {
+ _Ty* __element_ptr = __ptr + __idx; 
+ allocator_traits<_ElemAlloc>::construct(__elem_alloc, 
+  __element_ptr, 
+  __value[__idx]);
+ ++__constructed;
+   }
+   }
+  else
+   {
+ using _Tl = std::remove_extent_t<_Ty>;
+ for (_SizeType __idx = 0; __idx < __extent; ++__idx)
+   {
+ _Tl* __elem_ptr = __ptr[__idx];
+ __recursive_element_construct_1(__elem_alloc,
+ __elem_ptr, 
+ __constructed, 
+ extent_v<_Ty>,
+ __value[__idx]);
+   }
+   }
+}
+
+  template
+constexpr void
+__recursive_element_construct (_ElemAlloc& __elem_alloc, _Ty* __ptr,
+  __alloc_size<_ElemAlloc>& __constructed,
+  __alloc_size<_ElemAlloc> __extent,
+  const _Init& __value)
+{
+  using _SizeType = __alloc_size<_ElemAlloc>;
+  if constexpr (rank_v<_Ty> == 0)
+   {
+ for (_SizeType __idx = 0; __idx < __extent; ++__idx)
+   {
+ _Ty* __elem_ptr = __ptr + __idx;
+ allocator_traits<_ElemAlloc>::construct(__elem_alloc,
+ __elem_ptr,
+ __value);
+ ++__constructed;
+   }
+   }
+  else
+   {
+ using _Tl = std::remove_extent_t<_Ty>;
+ for (_SizeType __idx = 0; __idx

Re: [ PATCH ] [ C++ ] [ libstdc++ ] P1208r6 Merge source_location

2020-01-02 Thread JeanHeyd Meneide
On Thu, Jan 2, 2020 at 5:07 PM Jakub Jelinek  wrote:
>
> On Thu, Jan 02, 2020 at 04:57:01PM -0500, JeanHeyd Meneide wrote:
> > +#if defined(_GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION)
> > +# define __cpp_lib_source_location 201907L
> > +#elif defined(_GLIBCXX_HAVE_BUILTIN_LINE) && 
> > defined(_GLIBCXX_HAVE_BUILTIN_COLUMN)
> > +# define __cpp_lib_is_constant_evaluated 201907L
>
> How is __cpp_lib_is_constant_evaluated related to presence of __builtin_LINE
> and __builtin_COLUMN?

Oops. Sorry; fat-fingered the diff a little!
diff --git a/libstdc++-v3/include/Makefile.in 
b/libstdc++-v3/include/Makefile.in
index ae4a493ea65..c104ffb28ab 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -414,6 +414,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/source_location \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index f983743b052..6ca431b24ee 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -630,6 +630,7 @@ namespace std
 
 #if __GNUC__ >= 7
 // Assume these are available if the compiler claims to be a recent GCC:
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
@@ -637,6 +638,9 @@ namespace std
 # if __GNUC__ >= 9
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
+# if __GNUC__ >= 10
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
 #elif defined(__is_identifier) && defined(__has_builtin)
 // For non-GNU compilers:
 # if ! __is_identifier(__has_unique_object_representations)
@@ -654,6 +658,15 @@ namespace std
 # if ! __is_identifier(__is_same)
 #  define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same(T, U)
 # endif
+# if __has_builtin(__builtin_source_location)
+#  define _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION 1
+# endif
 #endif // GCC
 
 // PSTL configuration
diff --git a/libstdc++-v3/include/std/source_location 
b/libstdc++-v3/include/std/source_location
new file mode 100644
index 000..4c805df0dfa
--- /dev/null
+++ b/libstdc++-v3/include/std/source_location
@@ -0,0 +1,101 @@
+// Component for retrieving function, line and column source info. -*- C++ -*-
+
+// Copyright (C) 2019-2020 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file source_location
+ *  This is a Standard C++ Library header.
+ */
+
+//
+// P1208 source_location library
+// Contributed by ThePhD with <3
+//
+
+#ifndef _GLIBCXX_SOURCE_LOCATION
+#define _GLIBCXX_SOURCE_LOCATION 1
+
+#pragma GCC system_header
+
+#include 
+#include 
+
+#if __cplusplus > 201703L
+#ifdef _GLIBCXX_HAVE_BUILTIN_SOURCE_LOCATION
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+#define __cpp_lib_source_location 201907L
+
+  struct source_location
+  {
+  private:
+struct __impl
+{
+  const char *_M_file_name;
+  const char *_M_function_name;
+  unsigned int _M_line, _M_column;
+};
+
+  public:
+static consteval source_location
+current (const void *__src_loc_impl = __builtin_source_location ()) 
noexcept
+{
+  source_location __ret;
+  __ret._M_data = static_cast(__src_loc_impl);
+  return __ret;
+}
+
+constexpr
+source_location () noexcept
+: _M_data ()
+{ }
+
+constexpr const char *
+file_name () const noexcept
+{ return _M_data ? _M_data->_M_file_name : ""; }
+
+constexpr const char *
+function_name () const noexcept
+{ return _M_data ? _M_data->_M_function_name : ""; }
+
+constexpr uint_least32_t
+line () const noexcept
+{ return _M_data ? _M_data->_M_line : 0; }
+  
+constexpr uint_least32_t
+colu

[ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-15 Thread JeanHeyd Meneide
Attached is a patch for p1301 that improves in the way Jason Merrill
specified earlier
(https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00858.html), but it
keeps segfaulting on my build of GCC. I don't know what changes I've
made that cause it to segfault: it does so whenever the error()
function is called but the backtraces aren't showing me anything
conclusive.

The tests test what I expect them to and the output is fine, I just
can't get the segfaults to stop, so I'm putting the patch up so
someone can critique what I've written, or someone else to test it
too. Sorry for taking so long.

Thanks,
JeanHeyd
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e3c602fbb8d..fb05b5f8af0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
  else if (is_attribute_p ("deprecated", attr_name))
result = 201309;
  else if (is_attribute_p ("maybe_unused", attr_name)
-  || is_attribute_p ("nodiscard", attr_name)
   || is_attribute_p ("fallthrough", attr_name))
result = 201603;
  else if (is_attribute_p ("no_unique_address", attr_name)
   || is_attribute_p ("likely", attr_name)
   || is_attribute_p ("unlikely", attr_name))
result = 201803;
+ else if (is_attribute_p ("nodiscard", attr_name))
+   result = 201907;
  if (result)
attr_name = NULL_TREE;
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 364af72e68d..3365219636f 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"
 
 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1026,22 +1027,45 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
 
   tree rettype = TREE_TYPE (type);
   tree fn = cp_get_fndecl_from_callee (callee);
+  tree attr;
   if (implicit != ICV_CAST && fn
-  && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+  && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = (has_msg ?
+   G_("ignoring return value of %qD, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of %qD, "
+  "declared with attribute %%s"));
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value of %qD, "
- "declared with attribute nodiscard", fn))
+ format, fn, raw_msg))
inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
-  && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
+  && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES 
(rettype
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = has_msg ?
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %%s");
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring returned value of type %qT, "
- "declared with attribute nodiscard", rettype))
+ format, rettype, raw_msg))
{
  if (fn)
inform (DECL_SOURCE_LOCATION (fn),
@@ -1050,24 +1074,59 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
  "%qT declared here", rettype);
}
 }
-  else if (TREE_CODE (expr) == TARGET_EXPR
-  && lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
+  else if (TREE_CODE (expr) == TARGET_EXPR)
 {
   /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the
 result is used, so handle that case here.  */
-  if (fn)
+  if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
{
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value

Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-15 Thread JeanHeyd Meneide
I am also not very smart, wherein I attach patches that do not have the tests.

Sorry!
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e3c602fbb8d..fb05b5f8af0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
  else if (is_attribute_p ("deprecated", attr_name))
result = 201309;
  else if (is_attribute_p ("maybe_unused", attr_name)
-  || is_attribute_p ("nodiscard", attr_name)
   || is_attribute_p ("fallthrough", attr_name))
result = 201603;
  else if (is_attribute_p ("no_unique_address", attr_name)
   || is_attribute_p ("likely", attr_name)
   || is_attribute_p ("unlikely", attr_name))
result = 201803;
+ else if (is_attribute_p ("nodiscard", attr_name))
+   result = 201907;
  if (result)
attr_name = NULL_TREE;
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 364af72e68d..3365219636f 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"
 
 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1026,22 +1027,45 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
 
   tree rettype = TREE_TYPE (type);
   tree fn = cp_get_fndecl_from_callee (callee);
+  tree attr;
   if (implicit != ICV_CAST && fn
-  && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+  && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = (has_msg ?
+   G_("ignoring return value of %qD, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of %qD, "
+  "declared with attribute %%s"));
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value of %qD, "
- "declared with attribute nodiscard", fn))
+ format, fn, raw_msg))
inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
-  && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
+  && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES 
(rettype
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = has_msg ?
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %%s");
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring returned value of type %qT, "
- "declared with attribute nodiscard", rettype))
+ format, rettype, raw_msg))
{
  if (fn)
inform (DECL_SOURCE_LOCATION (fn),
@@ -1050,24 +1074,59 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
  "%qT declared here", rettype);
}
 }
-  else if (TREE_CODE (expr) == TARGET_EXPR
-  && lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
+  else if (TREE_CODE (expr) == TARGET_EXPR)
 {
   /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the
 result is used, so handle that case here.  */
-  if (fn)
+  if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
{
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value of %qD, "
- "declared with attribute %",
- fn))
-   inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ if (fn)
+   {
+ auto_diagnostic_group d;
+ if (warning_at (loc, OPT_Wunused_result,
+ "ignoring return value of %qD, "
+ "declared with attribute %",
+ fn))
+   inform (DECL_SOURCE_LOCATION (fn), "declared here");
+   

Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-16 Thread JeanHeyd Meneide
Dear Dave,

 Thanks for sharing all of that! It was very helpful to read it
over again, and it was helpful in IRC yesterday.

 As a bit of a "that was strange" moment, I ran the builds again
and did NOT do --disable-bootstrap with the patch on a different
machine. They built and ran fine, with no segfaults during calls to
error(...). I probably forgot to properly clean/build something in my
debugging environment, which caused most of the problems.

 I already assigned my Copyright to the FSF, so that part should
be fine! Is there anything else I should be doing?

Sincerely,
JeanHeyd

On Wed, Oct 16, 2019 at 8:51 AM David Malcolm  wrote:
>
> On Tue, 2019-10-15 at 20:31 -0400, JeanHeyd Meneide wrote:
> > Attached is a patch for p1301 that improves in the way Jason Merrill
> > specified earlier
> > (https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00858.html), but it
> > keeps segfaulting on my build of GCC. I don't know what changes I've
> > made that cause it to segfault: it does so whenever the error()
> > function is called but the backtraces aren't showing me anything
> > conclusive.
> >
> > The tests test what I expect them to and the output is fine, I just
> > can't get the segfaults to stop, so I'm putting the patch up so
> > someone can critique what I've written, or someone else to test it
> > too. Sorry for taking so long.
> >
> > Thanks,
> > JeanHeyd
>
> Thanks for posting these patches.
>
> I believe you're a new GCC contributor - welcome!
>
> Having said "welcome", for good or ill, GCC has some legalese that we
> have to follow - to get a patch accepted, see the "Legal Prerequisites"
> section of: https://gcc.gnu.org/contribute.html so you'll need to
> follow that at some point  (I hate having to say this).
>
> I got the impression on IRC yesterday that you were having some trouble
> getting your debugging environment set up - it sounded to me like
> you've been "making do" by adding print statements to the parser and
> recompiling each time.
>
> If that's the case, then the best next step is probably to figure out
> how to get you debugging cc1plus using a debugger.
>
> Normally, I run:
>   ./xgcc -B.
> and add  "-wrapper gdb,--args" to the command line so that the driver
> invokes gdb.
>
> Another way is to invoke gdb and have it directly invoke cc1plus:
>gdb --args ./cc1plus -quiet x.C
>
> In both cases, run it from /gcc
>
> See also:
> https://dmalcolm.fedorapeople.org/gcc/newbies-guide/debugging.html
> which has further hints and info on a "nicer" debugging experience.
>
> You mentioned that you normally use gdbserver, which makes me think
> that you're most comfortable using gdb from an IDE.  I'm not very
> familiar with gdbserver, but hopefully someone here knows the recipe
> for this that will let you comfortably debug the frontend - without
> needing to add print statements and recompile each time (ugh).
>
> Note that for hacking on the frontend and debugging, I normally
> configure gcc with --disable-bootstrap which saves a *lot* of time;
> similarly I also only build the "gcc" subdirectory and its dependencies
> (I still do a full bootstrap and regression test in a separate
> directory once I've got a candidate patch that I want to test properly
> before submitting to the mailing list).
>
> [I know that you know some/all of this, but I'm posting it here for the
> benefit of people reading the list archives]
>
> Hope this is helpful, and welcome again.
> Dave
>
>


Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-16 Thread JeanHeyd Meneide
Thanks, Jason! I fixed those last things and I put the changelog below
in the e-mail. I'll figure out how to write a good changelog in a
commit message on the command line soon. :D



2019-10-16  JeanHeyd Meneide 

gcc/

* escaped_string.h: New. Refactored out of tree.c to make more
broadly available (e.g. to parser.c, cvt.c).
* tree.c: remove escaped_string class

gcc/c-family

* c-lex.c - update attribute value

gcc/cp/

* tree.c: Implement p1301 - nodiscard("should have a reason"))
Added C++2a nodiscard string message handling.
Increase nodiscard argument handling max_length from 0
to 1.
* parser.c: add requirement that nodiscard only be seen
once in attribute-list
* cvt.c: add nodiscard message to output, if applicable
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e3c602fbb8d..fb05b5f8af0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
  else if (is_attribute_p ("deprecated", attr_name))
result = 201309;
  else if (is_attribute_p ("maybe_unused", attr_name)
-  || is_attribute_p ("nodiscard", attr_name)
   || is_attribute_p ("fallthrough", attr_name))
result = 201603;
  else if (is_attribute_p ("no_unique_address", attr_name)
   || is_attribute_p ("likely", attr_name)
   || is_attribute_p ("unlikely", attr_name))
result = 201803;
+ else if (is_attribute_p ("nodiscard", attr_name))
+   result = 201907;
  if (result)
attr_name = NULL_TREE;
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 364af72e68d..f2d2ba6cafb 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"
 
 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1026,22 +1027,45 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
 
   tree rettype = TREE_TYPE (type);
   tree fn = cp_get_fndecl_from_callee (callee);
+  tree attr;
   if (implicit != ICV_CAST && fn
-  && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+  && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = (has_msg ?
+   G_("ignoring return value of %qD, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of %qD, "
+  "declared with attribute %%s"));
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value of %qD, "
- "declared with attribute nodiscard", fn))
+ format, fn, raw_msg))
inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
-  && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
+  && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES 
(rettype
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = has_msg ?
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %%s");
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring returned value of type %qT, "
- "declared with attribute nodiscard", rettype))
+ format, rettype, raw_msg))
{
  if (fn)
inform (DECL_SOURCE_LOCATION (fn),
@@ -1180,7 +1204,7 @@ convert_to_void (tree expr, impl_conv_void impl

Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-17 Thread JeanHeyd Meneide
2019-10-17  JeanHeyd Meneide  

gcc/

* escaped_string.h (escaped_string): New header.
* tree.c (escaped_string): Remove escaped_string class.

gcc/c-family

* c-lex.c (c_common_has_attribute): Update attribute value.

gcc/cp/

* tree.c (handle_nodiscard_attribute): Implements p1301
  [[nodiscard("should have a reason")]].
  (handle_nodiscard_attribute) Added C++2a nodiscard string message.
  (std_attribute_table) Increase nodiscard argument handling
max_length from 0
  to 1.
* parser.c (cp_parser_check_std_attribute): Add requirement
that nodiscard
  only be seen once in attribute-list.
* cvt.c (maybe_warn_nodiscard): Add nodiscard message to
output, if applicable.
  (convert_to_void): Allow constructors to be nodiscard-able
(fixes paper-as-DR
  p1771).

gcc/testsuite/g++.dg/cpp2a

* nodiscard-construct.C: New test.
* nodiscard-once.C: New test.
* nodiscard-reason-nonstring.C: New test.
* nodiscard-reason-only-one.C: New test.
* nodiscard-reason.C: New test.
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e3c602fbb8d..fb05b5f8af0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
  else if (is_attribute_p ("deprecated", attr_name))
result = 201309;
  else if (is_attribute_p ("maybe_unused", attr_name)
-  || is_attribute_p ("nodiscard", attr_name)
   || is_attribute_p ("fallthrough", attr_name))
result = 201603;
  else if (is_attribute_p ("no_unique_address", attr_name)
   || is_attribute_p ("likely", attr_name)
   || is_attribute_p ("unlikely", attr_name))
result = 201803;
+ else if (is_attribute_p ("nodiscard", attr_name))
+   result = 201907;
  if (result)
attr_name = NULL_TREE;
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 364af72e68d..f2d2ba6cafb 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"
 
 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1026,22 +1027,45 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
 
   tree rettype = TREE_TYPE (type);
   tree fn = cp_get_fndecl_from_callee (callee);
+  tree attr;
   if (implicit != ICV_CAST && fn
-  && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+  && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = (has_msg ?
+   G_("ignoring return value of %qD, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of %qD, "
+  "declared with attribute %%s"));
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring return value of %qD, "
- "declared with attribute nodiscard", fn))
+ format, fn, raw_msg))
inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
-  && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
+  && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES 
(rettype
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_arg = args && TREE_CODE (TREE_VALUE (args)) == 
STRING_CST;
+  if (has_string_arg)
+msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
+  const bool has_msg = msg;
+  const char* format = has_msg ?
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %: %<%s%>") :
+   G_("ignoring return value of type %qT, "
+  "declared with attribute %%s");
+  const char* raw_msg = (has_msg ? static_cast(msg) : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
- "ignoring returned value of type %qT, "

Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-17 Thread JeanHeyd Meneide
Dear Jason,

On Thu, Oct 17, 2019 at 3:51 PM Jason Merrill  wrote:
>  > FAIL: g++.dg/cpp0x/gen-attrs-67.C  -std=c++11  (test for errors, line 8)
>  > FAIL: g++.dg/cpp1z/feat-cxx1z.C  -std=gnu++17 (test for excess errors)
>  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11 (test for excess errors)
>  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11  (test for warnings, line 12)
>  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11  (test for warnings, line 13)
>  > FAIL: g++.dg/cpp2a/feat-cxx2a.C   (test for excess errors)

 Sorry about that! I implemented a bit of a better warning to
cover gen-attrs-67, and bumped the feature test macro value checks in
the feat tests. The rest should be fine now too.

 Let me know if anything else seems off!

Best Wishes,
JeanHeyd Meneide

=======

2019-10-17  JeanHeyd Meneide  

gcc/

Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
* escaped_string.h (escaped_string): New header.
* tree.c (escaped_string): Remove escaped_string class.

gcc/c-family

Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
* c-lex.c (c_common_has_attribute): Update attribute value.

gcc/cp/

Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
* tree.c (handle_nodiscard_attribute) Added C++2a nodiscard
string message.
  (std_attribute_table) Increase nodiscard argument handling
max_length from 0
  to 1.
* parser.c (cp_parser_check_std_attribute): Add requirement
that nodiscard
  only be seen once in attribute-list.
  (cp_parser_std_attribute): Check that empty parenthesis lists are
  not specified for attributes that have max_length > 0 (e.g.
[[attr()]]).
* cvt.c (maybe_warn_nodiscard): Add nodiscard message to
output, if applicable.
  (convert_to_void): Allow constructors to be nodiscard-able
(fixes paper-as-DR
  p1771).

gcc/testsuite/g++.dg/cpp0x

Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
* gen-attrs-67.C: Test new error message for empty-parenthesis-list.

gcc/testsuite/g++.dg/cpp2a

Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
* nodiscard-construct.C: New test.
* nodiscard-once.C: New test.
* nodiscard-reason-nonstring.C: New test.
* nodiscard-reason-only-one.C: New test.
* nodiscard-reason.C: New test.


Re: [ C++ ] [ PATCH ] [ RFC ] p1301 - [[nodiscard("should have a reason")]]

2019-10-17 Thread JeanHeyd Meneide
... And I am very tired and forgot to attach the patch. Again. Sorry...!

On Fri, Oct 18, 2019 at 1:54 AM JeanHeyd Meneide
 wrote:
>
> Dear Jason,
>
> On Thu, Oct 17, 2019 at 3:51 PM Jason Merrill  wrote:
> >  > FAIL: g++.dg/cpp0x/gen-attrs-67.C  -std=c++11  (test for errors, line 8)
> >  > FAIL: g++.dg/cpp1z/feat-cxx1z.C  -std=gnu++17 (test for excess errors)
> >  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11 (test for excess errors)
> >  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11  (test for warnings, line 12)
> >  > FAIL: g++.dg/cpp1z/nodiscard4.C  -std=c++11  (test for warnings, line 13)
> >  > FAIL: g++.dg/cpp2a/feat-cxx2a.C   (test for excess errors)
>
>  Sorry about that! I implemented a bit of a better warning to
> cover gen-attrs-67, and bumped the feature test macro value checks in
> the feat tests. The rest should be fine now too.
>
>  Let me know if anything else seems off!
>
> Best Wishes,
> JeanHeyd Meneide
>
> ===
>
> 2019-10-17  JeanHeyd Meneide  
>
> gcc/
>
> Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
> * escaped_string.h (escaped_string): New header.
> * tree.c (escaped_string): Remove escaped_string class.
>
> gcc/c-family
>
> Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
> * c-lex.c (c_common_has_attribute): Update attribute value.
>
> gcc/cp/
>
> Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
> * tree.c (handle_nodiscard_attribute) Added C++2a nodiscard
> string message.
>   (std_attribute_table) Increase nodiscard argument handling
> max_length from 0
>   to 1.
> * parser.c (cp_parser_check_std_attribute): Add requirement
> that nodiscard
>   only be seen once in attribute-list.
>   (cp_parser_std_attribute): Check that empty parenthesis lists are
>   not specified for attributes that have max_length > 0 (e.g.
> [[attr()]]).
> * cvt.c (maybe_warn_nodiscard): Add nodiscard message to
> output, if applicable.
>   (convert_to_void): Allow constructors to be nodiscard-able
> (fixes paper-as-DR
>   p1771).
>
> gcc/testsuite/g++.dg/cpp0x
>
> Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
> * gen-attrs-67.C: Test new error message for empty-parenthesis-list.
>
> gcc/testsuite/g++.dg/cpp2a
>
> Implements p1301 [[nodiscard("should have a reason")]] + p1771 DR
> * nodiscard-construct.C: New test.
> * nodiscard-once.C: New test.
> * nodiscard-reason-nonstring.C: New test.
> * nodiscard-reason-only-one.C: New test.
> * nodiscard-reason.C: New test.
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e3c602fbb8d..fb05b5f8af0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
  else if (is_attribute_p ("deprecated", attr_name))
result = 201309;
  else if (is_attribute_p ("maybe_unused", attr_name)
-  || is_attribute_p ("nodiscard", attr_name)
   || is_attribute_p ("fallthrough", attr_name))
result = 201603;
  else if (is_attribute_p ("no_unique_address", attr_name)
   || is_attribute_p ("likely", attr_name)
   || is_attribute_p ("unlikely", attr_name))
result = 201803;
+ else if (is_attribute_p ("nodiscard", attr_name))
+   result = 201907;
  if (result)
attr_name = NULL_TREE;
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 364af72e68d..4df5fc49048 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"
 
 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1026,22 +1027,45 @@ maybe_warn_nodiscard (tree expr, impl_conv_void 
implicit)
 
   tree rettype = TREE_TYPE (type);
   tree fn = cp_get_fndecl_from_callee (callee);
+  tree attr;
   if (implicit != ICV_CAST && fn
-  && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+  && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
 {
+  escaped_string msg;
+  tree args = TREE_VALUE(attr);
+  const bool has_string_ar

[PATCH] [RFC] span-v2: using concepts, constraints and ranges:: instead of enable_if

2019-11-21 Thread JeanHeyd Meneide
This is an attempt to use concepts and constraints rather than
ranges::. It builds and run the tests I ran on x86_64 Linux decently
(albeit I'm still new at doing this). I wanted to get a feel for
whether or not this had been done right:

Thoughts?
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 6300de9e96d..7f7035ca64e 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -156,6 +156,7 @@ bits_headers = \
${bits_srcdir}/random.tcc \
${bits_srcdir}/range_access.h \
${bits_srcdir}/range_cmp.h \
+   ${bits_srcdir}/range_concepts.h \
${bits_srcdir}/refwrap.h \
${bits_srcdir}/regex.h \
${bits_srcdir}/regex.tcc \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index ae4a493ea65..475106ee69b 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -500,6 +500,7 @@ bits_headers = \
${bits_srcdir}/random.tcc \
${bits_srcdir}/range_access.h \
${bits_srcdir}/range_cmp.h \
+   ${bits_srcdir}/range_concepts.h \
${bits_srcdir}/refwrap.h \
${bits_srcdir}/regex.h \
${bits_srcdir}/regex.tcc \
diff --git a/libstdc++-v3/include/bits/iterator_concepts.h 
b/libstdc++-v3/include/bits/iterator_concepts.h
index 3843ba5d57f..c4a4e92fed0 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -71,6 +71,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  { *__t } -> __can_reference;
};
 
+template
+  concept __is_compatible_pointer = is_convertible<_RightType(*)[], 
_LeftType(*)[]>::value;
+
 // FIXME: needed due to PR c++/67704
 template<__detail::__dereferenceable _Tp>
   struct __iter_ref
diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index de074460c16..66697ffc354 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -34,6 +34,7 @@
 
 #if __cplusplus >= 201103L
 #include 
+#include 
 #include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -336,19 +337,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 ssize(const _Tp (&)[_Num]) noexcept
 { return _Num; }
 
-  // "why are these in namespace std:: and not __gnu_cxx:: ?"
-  // because if we don't put them here it's impossible to
-  // have implicit ADL with "using std::begin/end/size/data;".
-  template 
-constexpr auto
-__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
-{ return begin(__cont); }
-
-  template 
-constexpr auto
-__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
-{ return data(__cont); }
-
 #ifdef __cpp_lib_concepts
 namespace ranges
 {
@@ -869,10 +857,68 @@ namespace ranges
   template
 concept range = __detail::__range_impl<_Tp&>;
 
+  template
+using sentinel_t = decltype(ranges::end(std::declval<_Range&>()));
+
+  template
+using iterator_t = decltype(ranges::begin(std::declval<_Range&>()));
+
+  template
+using range_value_t = iter_value_t>;
+
+  template
+using range_reference_t = iter_reference_t>;
+
+  template
+using range_rvalue_reference_t
+  = iter_rvalue_reference_t>;
+
+  template
+using range_difference_t = iter_difference_t>;
+
+  namespace __detail
+  {
+template
+  concept __forwarding_range = range<_Tp> && __range_impl<_Tp>;
+  } // namespace __detail
+
   /// [range.sized] The sized_range concept.
   template
 concept sized_range = range<_Tp>
-  && requires(_Tp& __t) { ranges::size(__t); };
+  && requires(_Tp& __t) { ranges::size(__t); };template
+inline constexpr bool disable_sized_range = false;
+
+  // [range.refinements]
+  template
+concept output_range
+  = range<_Range> && output_iterator, _Tp>;
+
+  template
+concept input_range = range<_Tp> && input_iterator>;
+
+  template
+concept forward_range
+  = input_range<_Tp> && forward_iterator>;
+
+  template
+concept bidirectional_range
+  = forward_range<_Tp> && bidirectional_iterator>;
+
+  template
+concept random_access_range
+  = bidirectional_range<_Tp> && random_access_iterator>;
+
+  template
+concept contiguous_range
+  = random_access_range<_Tp> && contiguous_iterator>
+  && requires(_Tp& __t)
+  {
+   { ranges::data(__t) } -> same_as>>;
+  };
+
+  template
+concept common_range
+  = range<_Tp> && same_as, sentinel_t<_Tp>>;
 
 // [range.iter.ops] range iterator operations
 
@@ -1008,12 +1054,6 @@ namespace ranges
}
 }
 
-  template
-using iterator_t = decltype(ranges::begin(std::declval<_Range&>()));
-
-  template
-using range_difference_t = iter_difference_t>;
-
   template
 constexpr range_difference_t<_Range>
 distance(_Range&& __r)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 333d110b67e..a8b27764419 100644
--- a/libst

Re: [PATCH] [RFC] span-v2: using concepts, constraints and ranges:: instead of enable_if

2019-11-21 Thread JeanHeyd Meneide
Thank you for the review!

- I moved the concepts back into the class and changed them to
template aliases because class local concepts aren't a thing that
works.
 + They are not inline constexpr bools because that ICE's GCC
pretty hard, as you explained to me earlier, so we use ::value in some
places rather than _v
- I named the alias __is_array_convertible, to match what the intent
is, and named the template parameters very explicitly.
 + I moved it into type_traits, but I didn't change
bits/unique_ptr.h or shared_ptr yet because I'm not confident I can do
that quickly in one go.
 + (And it should probably be a different patch anyways, but it
should be in the right place when we introduce it here.)

-

2019-11-21  JeanHeyd "ThePhD" Meneide  

* include/std/span: Use concepts and ranges:: calls
  instead of enable_if and friends.
* include/std/ranges: tear basic concepts out and put in
  range_access.h for "ranges lite" internal header.
* include/std/type_traits: __is_array_convertible trait. Is common
  to unique/shared_ptr as well (preparation for changing
  unique/shared_ptr soon).
   * include/bits/range_access.h: Remove __adl_* versions
  of access functions.
diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index de074460c16..c0891c2f235 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -336,19 +336,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 ssize(const _Tp (&)[_Num]) noexcept
 { return _Num; }
 
-  // "why are these in namespace std:: and not __gnu_cxx:: ?"
-  // because if we don't put them here it's impossible to
-  // have implicit ADL with "using std::begin/end/size/data;".
-  template 
-constexpr auto
-__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
-{ return begin(__cont); }
-
-  template 
-constexpr auto
-__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
-{ return data(__cont); }
-
 #ifdef __cpp_lib_concepts
 namespace ranges
 {
@@ -869,10 +856,70 @@ namespace ranges
   template
 concept range = __detail::__range_impl<_Tp&>;
 
+  template
+using sentinel_t = decltype(ranges::end(std::declval<_Range&>()));
+
+  template
+using iterator_t = decltype(ranges::begin(std::declval<_Range&>()));
+
+  template
+using range_value_t = iter_value_t>;
+
+  template
+using range_reference_t = iter_reference_t>;
+
+  template
+using range_rvalue_reference_t
+  = iter_rvalue_reference_t>;
+
+  template
+using range_difference_t = iter_difference_t>;
+
+  namespace __detail
+  {
+template
+  concept __forwarding_range = range<_Tp> && __range_impl<_Tp>;
+  } // namespace __detail
+
   /// [range.sized] The sized_range concept.
   template
 concept sized_range = range<_Tp>
   && requires(_Tp& __t) { ranges::size(__t); };
+  
+  template
+inline constexpr bool disable_sized_range = false;
+
+  // [range.refinements]
+  template
+concept output_range
+  = range<_Range> && output_iterator, _Tp>;
+
+  template
+concept input_range = range<_Tp> && input_iterator>;
+
+  template
+concept forward_range
+  = input_range<_Tp> && forward_iterator>;
+
+  template
+concept bidirectional_range
+  = forward_range<_Tp> && bidirectional_iterator>;
+
+  template
+concept random_access_range
+  = bidirectional_range<_Tp> && random_access_iterator>;
+
+  template
+concept contiguous_range
+  = random_access_range<_Tp> && contiguous_iterator>
+  && requires(_Tp& __t)
+  {
+   { ranges::data(__t) } -> same_as>>;
+  };
+
+  template
+concept common_range
+  = range<_Tp> && same_as, sentinel_t<_Tp>>;
 
 // [range.iter.ops] range iterator operations
 
@@ -1008,12 +1055,6 @@ namespace ranges
}
 }
 
-  template
-using iterator_t = decltype(ranges::begin(std::declval<_Range&>()));
-
-  template
-using range_difference_t = iter_difference_t>;
-
   template
 constexpr range_difference_t<_Range>
 distance(_Range&& __r)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 333d110b67e..e1bf6eec5d0 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -56,64 +56,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 namespace ranges
 {
   // [range.range] The range concept.
-  // Defined in 
-  // template concept range;
-
-  template
-using sentinel_t = decltype(ranges::end(std::declval<_Range&>()));
-
-  template
-using range_value_t = iter_value_t>;
-
-  template
-using range_reference_t = iter_reference_t>;
-
-  template
-using range_rvalue_reference_t
-  = iter_rvalue_reference_t>;
-
-  namespace __detail
-  {
-template
-  concept __forwarding_range = range<_Tp> && __range_impl<_Tp>;
-  } // namespace __detail
-
   // [range.sized] The sized_range concept.
-  // D

[ PATCH ] [ C++ ] Implementing P0767 - deprecate POD

2019-12-03 Thread JeanHeyd Meneide
This patch implements deprecate POD for the C++ Standard Library,
bringing libstdc++ that much closer to 2020 conformance 🎉!

Hilariously, a small bug in the [[deprecated]] warning message was
found while implementing this patch, which drove me a bit insane for a
good 10 minutes until I realized what was going on:
https://godbolt.org/z/WwBNUx

Either way, here you go! Someone will probably have to fix the
template-class [[deprecated("foo")]] bug at some point too.

2019-12-03  JeanHeyd "ThePhD" Meneide  

* include/bits/c++config: Add new _GLIBCXX20_DEPRECATED macro.
* include/std/type_traits: Deprecate is_pod with message.
* testuite/20_util/is_pod/deprecated-2a.cc (new): test deprecation
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 7ccfc5f199d..5876b0b977b 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -78,6 +78,7 @@
 //   _GLIBCXX_USE_DEPRECATED
 //   _GLIBCXX_DEPRECATED
 //   _GLIBCXX17_DEPRECATED
+//   _GLIBCXX20_DEPRECATED( STRINGS... )
 #ifndef _GLIBCXX_USE_DEPRECATED
 # define _GLIBCXX_USE_DEPRECATED 1
 #endif
@@ -94,6 +95,12 @@
 # define _GLIBCXX17_DEPRECATED
 #endif
 
+#if defined(__DEPRECATED) && (__cplusplus > 201703L)
+# define _GLIBCXX20_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
+#else
+# define _GLIBCXX20_DEPRECATED(...) 
+#endif
+
 // Macros for ABI tag attributes.
 #ifndef _GLIBCXX_ABI_TAG_CXX11
 # define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 8e787a994c3..91269d1bd02 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -685,10 +685,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
"template argument must be a complete class or an unbounded array");
 };
 
-  /// is_pod
+  /// is_pod (deprecated C++2a)
   // Could use is_standard_layout && is_trivial instead of the builtin.
   template
-struct is_pod
+struct
+_GLIBCXX20_DEPRECATED("is_pod is deprecated in C++20: use 
is_standard_layout && is_trivial instead") 
+is_pod
 : public integral_constant
 {
   static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
@@ -3073,6 +3075,7 @@ template 
 template 
   inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
 template 
+  _GLIBCXX20_DEPRECATED("is_pod is deprecated in C++20: use 
is_standard_layout && is_trivial instead")
   inline constexpr bool is_pod_v = is_pod<_Tp>::value;
 template 
   inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
diff --git a/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc 
b/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc
new file mode 100644
index 000..9782c3f551d
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_pod/deprecated-2a.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2010-2019 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
+// .
+
+// { dg-do compile { target c++2a } }
+
+// { dg-prune-output "declared here" }
+
+#include 
+
+static_assert(std::is_pod::value); // { dg-warning "is deprecated" }
+static_assert(std::is_pod_v); // { dg-warning "is deprecated" }


Re: cp: implementation of p1301 for C++

2019-07-25 Thread JeanHeyd Meneide
 I think I got the tabs right...? You would not believe how unbelievably
hard it is, just to mail a diff!

-

07-24-2019ThePhD

gcc/

* escaped_string.h: New. Refactored out of tree.c to make more
broadly available (e.g. to parser.c, cvt.c).
* tree.c: remove escaped_string class

gcc/c-family

* c-lex.c - update attribute value

gcc/cp/

* tree.c: Implement p1301 - nodiscard("should have a reason"))
Added C++2a nodiscard string message handling.
Increase nodiscard argument handling max_length from 0
to 1. (error C++2a gated)
* parser.c: add requirement that nodiscard only be seen
once in attribute-list (C++2a gated)
* cvt.c: add nodiscard message to output, if applicable

-

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 851fd704e5d..f5870d095f2 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -345,24 +345,26 @@ c_common_has_attribute (cpp_reader *pfile)
attr_name = NULL_TREE;
   }
  }
-  else
-  {
-  /* Some standard attributes need special handling. */
-  if (is_attribute_p ("noreturn", attr_name))
-   result = 200809;
-  else if (is_attribute_p ("deprecated", attr_name))
-   result = 201309;
-  else if (is_attribute_p ("maybe_unused", attr_name)
-|| is_attribute_p ("nodiscard", attr_name)
-|| is_attribute_p ("fallthrough", attr_name))
-   result = 201603;
-  else if (is_attribute_p ("no_unique_address", attr_name)
-|| is_attribute_p ("likely", attr_name)
-|| is_attribute_p ("unlikely", attr_name))
-   result = 201803;
-  if (result)
-   attr_name = NULL_TREE;
-  }
+   else
+ {
+   /* Some standard attributes need special handling. */
+   if (is_attribute_p ("noreturn", attr_name))
+ result = 200809;
+   else if (is_attribute_p ("deprecated", attr_name))
+ result = 201309;
+   else if (is_attribute_p ("maybe_unused", attr_name)
+|| is_attribute_p ("fallthrough", attr_name))
+ result = 201603;
+   else if (is_attribute_p ("no_unique_address", attr_name)
+|| is_attribute_p ("likely", attr_name)
+|| is_attribute_p ("unlikely", attr_name))
+ result = 201803;
+   else if (is_attribute_p ("nodiscard", attr_name))
+ result = 201907; /* placeholder until C++20 Post-Cologne Working
Draft. */
+
+   if (result)
+ attr_name = NULL_TREE;
+ }
 }
if (attr_name)
 {
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 23d2aabc483..4a5128c76a1 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see
#include "convert.h"
#include "stringpool.h"
#include "attribs.h"
+#include "escaped_string.h"
static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
static tree build_type_conversion (tree, tree);
@@ -1026,49 +1027,99 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
tree rettype = TREE_TYPE (type);
tree fn = cp_get_fndecl_from_callee (callee);
- if (implicit != ICV_CAST && fn
- && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
- {
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wunused_result,
-"ignoring return value of %qD, "
-"declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
- }
- else if (implicit != ICV_CAST
-  && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
- {
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wunused_result,
-"ignoring returned value of type %qT, "
-"declared with attribute nodiscard", rettype))
- {
-  if (fn)
-  inform (DECL_SOURCE_LOCATION (fn),
-"in call to %qD, declared here", fn);
-  inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
-"%qT declared here", rettype);
- }
- }
- else if (TREE_CODE (expr) == TARGET_EXPR
-  && lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
- {
- /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the
-  result is used, so handle that case here. */
- if (fn)
- {
-  auto_diagnostic_group d;
-  if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute %",
-  fn))
-  inform (DECL_SOURCE_LOCATION (fn), "declared here");
- }
- else
- warning_at (loc, OPT_Wunused_result,
-"ignoring return value of function "
-"declared with attribute %");
- }
+ if (implicit != ICV_CAST && fn
+   && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
+   {
+ tree attr = DECL_ATTRIBUTES (fn);
+ escaped_string msg;
+ if (attr)
+   msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+ bool has_msg = static_cast(msg);
+ const char* format = (has_msg ?
+   "ignoring return value of %qD, "
+   "declared with attribute %: %<%s%>" :
+   "ignoring return value of %qD, "
+   "declared with attribute %%s");
+ const char* raw_msg = (has_msg ? (const char*)msg : "");
+ auto_diagnostic_group d;
+ if (warning_at (loc, OPT_Wunused_result,
+  format, fn, raw_msg))
+   {
+ inform (DEC

Re: cp: implementation of p1301 for C++

2019-07-25 Thread JeanHeyd Meneide
The HTML formatting was off (again), so I used git send-email as someone
recommended to me in the IRC. Patch is here:
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01670.html

I... think it's good, there? Apologies for all the noise; it's a bit hard
getting used to these tools.

Sincerely,
JeanHeyd


[ PATCH ] C++20

2019-08-30 Thread JeanHeyd Meneide
This patch implements  as it currently exists in the C++20 Working Draft.

Notes:
- __gnu_cxx::__normal_iterator is not fully constexpr, so its not used here
- P1394 might be slated to end up in C++20 per National Body Comments.
Therefore, an early implementation is left in an
implementation-defined _GLIBCXX_P1394 define.

2019-08-30  JeanHeyd "ThePhD" Meneide  

* include/std/span: Implement the entirety of span.
* include/bits/range_access.h: Add __adl_* versions of access functions.
* testsuite/23_containers/span/everything.cc: constexpr and
non-constexpr tests.
* include/Makefile.in: Add span to install.
* include/Makefile.am: Likewise


ThePhD.span.patch
Description: Binary data


Re: [ PATCH ] C++20

2019-08-30 Thread JeanHeyd Meneide
On Fri, Aug 30, 2019 at 3:41 PM Jonathan Wakely  wrote:
>
> On 30/08/19 15:22 -0400, JeanHeyd Meneide wrote:
> >This patch implements  as it currently exists in the C++20 Working 
> >Draft.
>
> Nice!
>
>
> >Notes:
> >- __gnu_cxx::__normal_iterator is not fully constexpr, so its not used here
>
> I'd prefer to make __normal_iterator constexpr, and use it.
> It needs to be constexpr anyway for string and vector.
> ...

Alright, thank you for the feedback. I fixed it up!

Tested x86_64-pc-linux-gnu.

2019-08-30  JeanHeyd "ThePhD" Meneide  

* include/std/span: Implement the entirety of span.
* include/bits/stl_iterator.h: __gnu_cxx::__normal_iterator is now constexpr-qualified for C++11+.
   * include/bits/range_access.h: Add __adl_* versions of access functions.
* testsuite/23_containers/span/everything.cc: constexpr and
non-constexpr tests.
* include/Makefile.in: Add span to install.
* include/Makefile.am: Likewise
diff --git a/.gitignore b/.gitignore
index d9d3967a12c..fd116c362ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,3 +57,7 @@ REVISION
 /mpc*
 /gmp*
 /isl*
+
+# ignore sprinkled in dev files that keep popping up
+.vscode/
+.vs/
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3fe80f32cc4..b8b786d9260 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -68,6 +68,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index b675d356cd4..cd1e9df5482 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -412,6 +412,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index d1e74711433..3acaebadcf1 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -318,6 +318,72 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #endif // C++17
 
+#if __cplusplus > 201703L
+  // "why are these in namespace std:: and not __gnu_cxx:: ?"
+  // because if we don't put them here it's impossible to 
+  // have implicit ADL with "using std::begin/end/size/data;".
+  template 
+constexpr auto
+__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
+{ return begin(__cont); }
+  
+  template 
+constexpr auto
+__adl_end(_Container& __cont) noexcept(noexcept(end(__cont)))
+{ return end(__cont); }
+  
+  template 
+constexpr auto
+__adl_cbegin(_Container& __cont) noexcept(noexcept(cbegin(__cont)))
+{ return cbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_cend(_Container& __cont) noexcept(noexcept(cend(__cont)))
+{ return cend(__cont); }
+
+  template 
+constexpr auto
+__adl_rbegin(_Container& __cont) noexcept(noexcept(rbegin(__cont)))
+{ return rbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_rend(_Container& __cont) noexcept(noexcept(rend(__cont)))
+{ return rend(__cont); }
+  
+  template 
+constexpr auto
+__adl_crbegin(_Container& __cont) noexcept(noexcept(crbegin(__cont)))
+{ return crbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_crend(_Container& __cont) noexcept(noexcept(crend(__cont)))
+{ return crend(__cont); }
+  
+  template 
+constexpr auto
+__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
+{ return data(__cont); }
+  
+  template 
+constexpr auto
+__adl_cdata(_Container& __cont) noexcept(noexcept(cdata(__cont)))
+{ return cdata(__cont); }
+  
+  template 
+constexpr auto
+__adl_size(_Container& __cont) noexcept(noexcept(size(__cont)))
+{ return size(__cont); }
+  
+  template 
+constexpr auto
+__adl_empty(_Container& __cont) noexcept(noexcept(empty(__cont)))
+{ return empty(__cont); }
+  
+#endif // C++20
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index 8ab0d72b0c2..4d432da0c6b 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -803,51 +803,51 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   : _M_current(_Iterator()) { }
 
   explicit
-  __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
+  _GLIBCXX_CONSTEXPR __normal_iterator(const _Iterator&

Re: [ PATCH ] C++20

2019-08-30 Thread JeanHeyd Meneide
Ahem -- we were supposed to use the 20 version of the constexpr macro,
not the base one.
I will note that, for some reason, the default constructor was already
constexpr, so we don't change that one!

On Fri, Aug 30, 2019 at 5:11 PM JeanHeyd Meneide
 wrote:
>
> On Fri, Aug 30, 2019 at 3:41 PM Jonathan Wakely  wrote:
> >
> > On 30/08/19 15:22 -0400, JeanHeyd Meneide wrote:
> > >This patch implements  as it currently exists in the C++20 Working 
> > >Draft.
> >
> > Nice!
> >
> >
> > >Notes:
> > >- __gnu_cxx::__normal_iterator is not fully constexpr, so its not used here
> >
> > I'd prefer to make __normal_iterator constexpr, and use it.
> > It needs to be constexpr anyway for string and vector.
> > ...
>
> Alright, thank you for the feedback. I fixed it up!
>
> Tested x86_64-pc-linux-gnu.
>
> 2019-08-30  JeanHeyd "ThePhD" Meneide  
>
> * include/std/span: Implement the entirety of span.
> * include/bits/stl_iterator.h: __gnu_cxx::__normal_iterator C> is now constexpr-qualified for C++11+.
>* include/bits/range_access.h: Add __adl_* versions of access 
> functions.
> * testsuite/23_containers/span/everything.cc: constexpr and
> non-constexpr tests.
> * include/Makefile.in: Add span to install.
> * include/Makefile.am: Likewise
diff --git a/.gitignore b/.gitignore
index d9d3967a12c..fd116c362ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,3 +57,7 @@ REVISION
 /mpc*
 /gmp*
 /isl*
+
+# ignore sprinkled in dev files that keep popping up
+.vscode/
+.vs/
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3fe80f32cc4..b8b786d9260 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -68,6 +68,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index b675d356cd4..cd1e9df5482 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -412,6 +412,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index d1e74711433..3acaebadcf1 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -318,6 +318,72 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #endif // C++17
 
+#if __cplusplus > 201703L
+  // "why are these in namespace std:: and not __gnu_cxx:: ?"
+  // because if we don't put them here it's impossible to 
+  // have implicit ADL with "using std::begin/end/size/data;".
+  template 
+constexpr auto
+__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
+{ return begin(__cont); }
+  
+  template 
+constexpr auto
+__adl_end(_Container& __cont) noexcept(noexcept(end(__cont)))
+{ return end(__cont); }
+  
+  template 
+constexpr auto
+__adl_cbegin(_Container& __cont) noexcept(noexcept(cbegin(__cont)))
+{ return cbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_cend(_Container& __cont) noexcept(noexcept(cend(__cont)))
+{ return cend(__cont); }
+
+  template 
+constexpr auto
+__adl_rbegin(_Container& __cont) noexcept(noexcept(rbegin(__cont)))
+{ return rbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_rend(_Container& __cont) noexcept(noexcept(rend(__cont)))
+{ return rend(__cont); }
+  
+  template 
+constexpr auto
+__adl_crbegin(_Container& __cont) noexcept(noexcept(crbegin(__cont)))
+{ return crbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_crend(_Container& __cont) noexcept(noexcept(crend(__cont)))
+{ return crend(__cont); }
+  
+  template 
+constexpr auto
+__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
+{ return data(__cont); }
+  
+  template 
+constexpr auto
+__adl_cdata(_Container& __cont) noexcept(noexcept(cdata(__cont)))
+{ return cdata(__cont); }
+  
+  template 
+constexpr auto
+__adl_size(_Container& __cont) noexcept(noexcept(size(__cont)))
+{ return size(__cont); }
+  
+  template 
+constexpr auto
+__adl_empty(_Container& __cont) noexcept(noexcept(empty(__cont)))
+{ return empty(__cont); }
+  
+#endif // C++20
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/include/bits/stl_itera

Re: [ PATCH ] C++20

2019-09-04 Thread JeanHeyd Meneide
 Thank you for the thorough review!

On Tue, Sep 3, 2019 at 9:31 AM Jonathan Wakely  wrote:
> It looks like__adl_begin and __adl_end should be guarded by #ifdef
> _GLIBCXX_P1394 because they're not needed otherwise.

 I'm absolutely going to need it for the bit data structures (and
in tuning up other parts of the library). It will also be important
for things that need to behave nicely when working with things needing
[range.access] internally in libstdc++,
while we wait for the cmcstl2 implementation. I did gate
__adl_to_address behind p1394, though, because that is definitely
specific to that paper (and its friend, p1474).

 Let me know if I missed anything!

 Tested on x64_86 Linux with 23_containers/* tests.
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3fe80f32cc4..b8b786d9260 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -68,6 +68,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index b675d356cd4..cd1e9df5482 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -412,6 +412,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
+   ${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
diff --git a/libstdc++-v3/include/bits/range_access.h 
b/libstdc++-v3/include/bits/range_access.h
index d1e74711433..a80ec48248f 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -318,6 +318,78 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #endif // C++17
 
+#if __cplusplus > 201703L
+  // "why are these in namespace std:: and not __gnu_cxx:: ?"
+  // because if we don't put them here it's impossible to 
+  // have implicit ADL with "using std::begin/end/size/data;".
+  template 
+constexpr auto
+__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
+{ return begin(__cont); }
+  
+  template 
+constexpr auto
+__adl_end(_Container& __cont) noexcept(noexcept(end(__cont)))
+{ return end(__cont); }
+  
+  template 
+constexpr auto
+__adl_cbegin(_Container& __cont) noexcept(noexcept(cbegin(__cont)))
+{ return cbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_cend(_Container& __cont) noexcept(noexcept(cend(__cont)))
+{ return cend(__cont); }
+
+  template 
+constexpr auto
+__adl_rbegin(_Container& __cont) noexcept(noexcept(rbegin(__cont)))
+{ return rbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_rend(_Container& __cont) noexcept(noexcept(rend(__cont)))
+{ return rend(__cont); }
+  
+  template 
+constexpr auto
+__adl_crbegin(_Container& __cont) noexcept(noexcept(crbegin(__cont)))
+{ return crbegin(__cont); }
+  
+  template 
+constexpr auto
+__adl_crend(_Container& __cont) noexcept(noexcept(crend(__cont)))
+{ return crend(__cont); }
+  
+  template 
+constexpr auto
+__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
+{ return data(__cont); }
+  
+  template 
+constexpr auto
+__adl_cdata(_Container& __cont) noexcept(noexcept(cdata(__cont)))
+{ return cdata(__cont); }
+  
+  template 
+constexpr auto
+__adl_size(_Container& __cont) noexcept(noexcept(size(__cont)))
+{ return size(__cont); }
+  
+  template 
+constexpr auto
+__adl_empty(_Container& __cont) noexcept(noexcept(empty(__cont)))
+{ return empty(__cont); }
+  
+#if defined(_GLIBCXX_P1394) && _GLIBCXX_P1394
+  template 
+constexpr auto
+__adl_to_address(_Container& __cont) noexcept(noexcept(to_address(__cont)))
+{ return to_address(__cont); }
+#endif // P1394 and new contiguous_iterator requirements 
[iterator.concept.contiguous]
+#endif // C++20
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index 8ab0d72b0c2..e29775a42c5 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -446,7 +446,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus >= 201103L
   template
-_GLIBCXX20_CONSTEXPR auto
+_GLIBCXX20_CONSTEXPR
+auto
 __niter_base(reverse_iterator<_Iterator> __it)
 -> decltype(__make_reverse_iterator(__niter_base(__it.base(
 { return __make_reverse_iterator(__niter_base(__it.base())); }
@@ -457,7 +458,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
 
   template
-_GLIBCXX20_CONSTEXPR auto
+_GLIBCXX20_CONSTEXPR
+auto
 __miter_base(reverse_iterator<_Iterator> __it)
 -> decltype(__make_

cp: implementation of p1301 for C++

2019-07-20 Thread JeanHeyd Meneide
Dear GCC Community,

 This patch implements the recently accepted p1301: [[nodiscard("should
have a reason")]]. Aaron Ballman implemented it for Clang in
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190715/280158.html
-- this is in preparation for a paper that will soon go to the C Committee
to keep feature-parity with C++ (the C2x draft already has attributes with
syntax exactly like C++).

Comments welcome: this is my first patch, and probably needs a lot of
help. This is also part of my Google Summer of Code training, to get used
to submitting and sending patches on the gcc-patches list.

Sincerely,
ThePhD



diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index e6452542bcc..3db90ec6c66 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-20  ThePhD  
+
+ * c-family/c-lex.c: increase [[nodiscard]] feature macro value (final
value pending post-Cologne mailing)
+
 2019-07-20  Jakub Jelinek  

  * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_LOOP.

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 851fd704e5d..f2c0b62c95b 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
   else if (is_attribute_p ("deprecated", attr_name))
  result = 201309;
   else if (is_attribute_p ("maybe_unused", attr_name)
-   || is_attribute_p ("nodiscard", attr_name)
|| is_attribute_p ("fallthrough", attr_name))
  result = 201603;
   else if (is_attribute_p ("no_unique_address", attr_name)
|| is_attribute_p ("likely", attr_name)
|| is_attribute_p ("unlikely", attr_name))
  result = 201803;
+  else if (is_attribute_p ("nodiscard", attr_name))
+ result = 201907; /* placeholder until C++20 Post-Cologne Working Draft. */
   if (result)
  attr_name = NULL_TREE;
 }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d645cdef147..9877b1af517 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,17 @@
+2019-07-20  ThePhD  
+
+ * escaped_string.h: New. Refactored out of tree.c to make more
+ broadly available (e.g. to parser.c, cvt.c).
+ * tree.c: Implement p1301 - nodiscard("should have a reason"))
+ Moved escaped_string class for working with attributes to
+ dedicated header.
+ Added C++2a nodiscard string message handling.
+ Increase nodiscard argument handling max_length from 0
+ to 1. (error C++2a gated)
+ * parser.c: add requirement that nodiscard only be seen
+ once in attribute-list (C++2a gated)
+ * cvt.c: add nodiscard message to output, if applicable
+
 2019-07-20  Jason Merrill  

  * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 23d2aabc483..aa4816f3a4f 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"

 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1029,19 +1030,29 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
   if (implicit != ICV_CAST && fn
   && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
 {
-  auto_diagnostic_group d;
+  tree attr = DECL_ATTRIBUTES (fn);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ "ignoring return value of %qD, "
+ "declared with attribute nodiscard%s%s", fn, (has_msg
? ": " : ""), (has_msg ? (const char*)msg : "")))
+inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
&& lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
 {
+  tree attr = TYPE_ATTRIBUTES (rettype);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring returned value of type %qT, "
-  "declared with attribute nodiscard", rettype))
+  "ignoring returned value of type %qT, "
+  "declared with attribute nodiscard%s%s", rettype,
(has_msg ? ": " : ""), (has_msg ? (const char*)msg : "")))
  {
   if (fn)
 inform (DECL_SOURCE_LOCATION (fn),
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5c379aaf58d..d66d13615fc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26399,13 +26399,26 @@ cp_parser_check_std_attribute (tree attributes,
tree attribute)
 {
   tree name =

Re: cp: implementation of p1301 for C++

2019-07-21 Thread JeanHeyd Meneide
I think I managed to fix all of the issues. Do let me know if I missed
anything!
--
diff --git a/.gitignore b/.gitignore
index b53f60db792..8988746a314 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,6 @@ REVISION
 /mpc*
 /gmp*
 /isl*
+
+# ignore some editor-specific files
+.vscode/*
\ No newline at end of file
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 711a31ea597..1c70f9d769f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -52,6 +52,12 @@
  * gcc/config/or1k/predicates.md (volatile_mem_operand): New.
  (reg_or_mem_operand): New.

+2019-07-22  ThePhD  
+
+ p1301
+ * escaped_string.h: New. Refactored out of tree.c to make more
+ broadly available (e.g. to parser.c, cvt.c).
+
 2019-07-21  Iain Sandoe  

  * config/rs6000/rs6000.c (TARGET_NO_PROTOTYPE): Move from here...
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index e6452542bcc..0c3bdbc2fd1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-22  ThePhD  
+
+ p1301
+ * c-family/c-lex.c: increase [[nodiscard]] feature macro
+ value (final value pending post-Cologne mailing)
+
 2019-07-20  Jakub Jelinek  

  * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_LOOP.
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 851fd704e5d..f2c0b62c95b 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
   else if (is_attribute_p ("deprecated", attr_name))
  result = 201309;
   else if (is_attribute_p ("maybe_unused", attr_name)
-   || is_attribute_p ("nodiscard", attr_name)
|| is_attribute_p ("fallthrough", attr_name))
  result = 201603;
   else if (is_attribute_p ("no_unique_address", attr_name)
|| is_attribute_p ("likely", attr_name)
|| is_attribute_p ("unlikely", attr_name))
  result = 201803;
+  else if (is_attribute_p ("nodiscard", attr_name))
+ result = 201907; /* placeholder until C++20 Post-Cologne Working Draft. */
   if (result)
  attr_name = NULL_TREE;
 }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d645cdef147..b6aa7f543f6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,14 @@
+2019-07-22  ThePhD  
+
+ p1301
+ * tree.c: Implement p1301 - nodiscard("should have a reason"))
+ Added C++2a nodiscard string message handling.
+ Increase nodiscard argument handling max_length from 0
+ to 1. (error C++2a gated)
+ * parser.c: add requirement that nodiscard only be seen
+ once in attribute-list (C++2a gated)
+ * cvt.c: add nodiscard message to output, if applicable
+
 2019-07-20  Jason Merrill  

  * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 23d2aabc483..e473025bb66 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"

 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1029,26 +1030,42 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
   if (implicit != ICV_CAST && fn
   && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
 {
+  tree attr = DECL_ATTRIBUTES (fn);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+  const char* pre_msg = (has_msg ? ": %<" : "");
+  const char* raw_msg = (has_msg ? (const char*)msg : "");
+  const char* post_msg = (has_msg ? "%>" : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ "ignoring return value of %qD, "
+ "declared with attribute %qE%s%s%s", fn, attr,
pre_msg, raw_msg, post_msg))
+inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
&& lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
 {
+  tree attr = TYPE_ATTRIBUTES (rettype);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+  const char* pre_msg = (has_msg ? ": %<" : "");
+  const char* raw_msg = (has_msg ? (const char*)msg : "");
+  const char* post_msg = (has_msg ? "%>" : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring returned value of type %qT, "
-  "declared with attribute nodiscard", rettype))
- {
-  if (fn)
-inform (DECL_SOURCE_LOCATION (fn),
-"in call to %qD, declared here", fn);
-  inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
-  "%qT declared here", rettype);
- }
+  "ignoring returned valu

Re: cp: implementation of p1301 for C++

2019-07-21 Thread JeanHeyd Meneide
Oops. I learned that %< and %> do not get applied as part of the string
arguments, only the initial format string. So, updated patch:
-
diff --git a/.gitignore b/.gitignore
index b53f60db792..8988746a314 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,6 @@ REVISION
 /mpc*
 /gmp*
 /isl*
+
+# ignore some editor-specific files
+.vscode/*
\ No newline at end of file
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 711a31ea597..1c70f9d769f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -52,6 +52,12 @@
  * gcc/config/or1k/predicates.md (volatile_mem_operand): New.
  (reg_or_mem_operand): New.

+2019-07-22  ThePhD  
+
+ p1301
+ * escaped_string.h: New. Refactored out of tree.c to make more
+ broadly available (e.g. to parser.c, cvt.c).
+
 2019-07-21  Iain Sandoe  

  * config/rs6000/rs6000.c (TARGET_NO_PROTOTYPE): Move from here...
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index e6452542bcc..0c3bdbc2fd1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-22  ThePhD  
+
+ p1301
+ * c-family/c-lex.c: increase [[nodiscard]] feature macro
+ value (final value pending post-Cologne mailing)
+
 2019-07-20  Jakub Jelinek  

  * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_LOOP.
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 851fd704e5d..f2c0b62c95b 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
   else if (is_attribute_p ("deprecated", attr_name))
  result = 201309;
   else if (is_attribute_p ("maybe_unused", attr_name)
-   || is_attribute_p ("nodiscard", attr_name)
|| is_attribute_p ("fallthrough", attr_name))
  result = 201603;
   else if (is_attribute_p ("no_unique_address", attr_name)
|| is_attribute_p ("likely", attr_name)
|| is_attribute_p ("unlikely", attr_name))
  result = 201803;
+  else if (is_attribute_p ("nodiscard", attr_name))
+ result = 201907; /* placeholder until C++20 Post-Cologne Working Draft. */
   if (result)
  attr_name = NULL_TREE;
 }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d645cdef147..b6aa7f543f6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,14 @@
+2019-07-22  ThePhD  
+
+ p1301
+ * tree.c: Implement p1301 - nodiscard("should have a reason"))
+ Added C++2a nodiscard string message handling.
+ Increase nodiscard argument handling max_length from 0
+ to 1. (error C++2a gated)
+ * parser.c: add requirement that nodiscard only be seen
+ once in attribute-list (C++2a gated)
+ * cvt.c: add nodiscard message to output, if applicable
+
 2019-07-20  Jason Merrill  

  * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 23d2aabc483..d89b6bcf07a 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"

 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1029,26 +1030,40 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
   if (implicit != ICV_CAST && fn
   && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
 {
+  tree attr = DECL_ATTRIBUTES (fn);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+  const char* pre_msg = (has_msg ? ": " : "");
+  const char* raw_msg = (has_msg ? (const char*)msg : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ "ignoring return value of %qD, "
+ "declared with attribute %%s%s", fn,
pre_msg, raw_msg))
+inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
&& lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
 {
+  tree attr = TYPE_ATTRIBUTES (rettype);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+  const char* pre_msg = (has_msg ? ": " : "");
+  const char* raw_msg = (has_msg ? (const char*)msg : "");
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring returned value of type %qT, "
-  "declared with attribute nodiscard", rettype))
- {
-  if (fn)
-inform (DECL_SOURCE_LOCATION (fn),
-"in call to %qD, declared here", fn);
-  inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
-  "%qT declared here", rettype);
- }
+  "ignoring returned value of type %qT, "
+  "declared with attribute %%s%s",
retty

Re: [RFC] [C]New syntax for the argument of counted_by attribute for C language

2025-03-13 Thread JeanHeyd Meneide
On Thu, Mar 13, 2025 Qing Zhao  wrote:

> ...
>
> Is N3188 the following:
> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3188.htm
>
> What’s the status of this proposal?


 N3188 was discussed during the January 2024 Meeting in Strasbourg,
France. There was "along the lines" (opinion poll) consensus for more work
to be done:

> *Straw poll (opinion):* Would WG14 like to add something along the lines
of N3188 to C2y?
> 10 / 3 / 5

 You can read the minutes here:
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3227.htm#59-n3188-identifying-array-length-state

Best Wishes,
JeanHeyd


Re: [RFC] [C]New syntax for the argument of counted_by attribute for C language

2025-03-13 Thread JeanHeyd Meneide
On Thu, Mar 13, 2025 Martin Uecker  wrote:

> ...
>
> So it seems to be a possible way forward while avoiding
> language divergence and without introducing anything too novel
> in either language.
>
> (But others still have concerns about .n and prefer __self__.)


 I would like to gently push back about __self__, or __self, or self,
because all of these identifiers are fairly common identifiers in code.
When I writing the paper for __self_func (
https://thephd.dev/_vendor/future_cxx/papers/C%20-%20__self_func.html ), I
searched GitHub and other source code indexing and repository services:
__self, __self__, and self has a substantial amount of uses. If there's an
alternative spelling to consider, I think that would be helpful.

I would also like to offer that other people have approached me about
`::` as a way to help disambiguate identifiers and prevent local shadowing
in macros ( see: https://github.com/ThePhD/future_cxx/issues/69 ). However,
I don't think it helps with the case of this GCC extension:

int main () {
int n = 1; // a local variable n
struct foo {
int n; // a member variable n
int a[n + 10];  // for VLA, this n refers to the local variable n.
//char *b __attribute__ ((counted_by(n + 10)))
// for counted_by, this n refers to the member variable n.
};
}

  If you use `::n`, this allows you to reference a global variable. But
the contentious `n` here isn't a global variable, it's a local. So it's not
of much help here. If you stack another "n" at the global scope, you then
have another problem:

extern int n;
int main () {
int n = 1; // a local variable n, shadows global
struct foo {
int n; // a member variable n
int a[n + 10];  // for VLA, this n refers to the local variable n.
//char *b __attribute__ ((counted_by(n + 10)))
// for counted_by, this n refers to the member variable n.
};
}

Now, even if you use C++-style `::n`, and then use the rules proposed by
context-sensitivity, it becomes impossible to refer to the local variable
outside of the struct without additional annotation. You get the opposite
of this problem with `${KEYWORD}.n` (${KEYWORD} as a placeholder for
__self, since I still have the above-named problems with __self): it
enables referring to the structure variable with ${KEYWORD}, and the local
variable with nothing, but still leaves the global variable as
non-referenceable anymore. Part of this problem is self-inflicted: VLAs in
structures are a GNU extension and not an ISO C feature (for reasons like
this one). But it's still technically a problem, and we can't necessarily
step on GCC's affordance to make an extension in this space, so whatever we
come up with we will have both problems to fix.

 I see 2 plausible ways forward, though I've only thought about this
for 4 days:

 (0) Accept that Yeoul (and the others) are correct in that issuing an
error (diagnostic) for this case would be better. Effectively, it's just
bad code and you ask the user to change the local variable from e.g. `n`,
which is something they should have control over (theoretically). Then,
standardize `::n` to refer to the global. The local variable could have a
different name, the name in the structure might be similar to a global (but
is found by counted_by's lookup), and the global variable has to be named
explicitly with `::n". This does not necessarily solve the forward
reference problem, but all solutions proposed here require delayed
resolution (especially to deal with the common struct case), so this seems
like a moot point in-general.

 (1) Accept that we need ${KEYWORD}, or ${DOT} , to refer to locals.
This does not solve the problem where a local variable shadows a global
variable, so even if this path is taken I would still suggest `::n` to go
with it, so that we can solve the problem where a local variable shadows a
global variable. Then there's no new real "lookup rule", so people who feel
like we're violating C's core design space might feel less uneasy because
you have to use the new syntax (a keyword or `.`) to access in-struct
things. This still has a forward reference problem, so it's once again moot
whether or not the forward reference problem can be solved here.

 The (0) solution can be seen as more "natural"; there's no dots, no
keyword, but it requires a potential change in local variables for
conflicting cases. `::global` comes along for the ride as the way to
separate member fields from globals. I could see this working and, as I
understand it, this is the choice Clang was currently progressing with (?).

 The (1) solution can be seen as less "natural"; it requires extra
syntax to say what is, overwhelmingly, the common use case and ISO
standard-supported use case to make way for a pathological GNU extension in
VLA members. It becomes a bit more natural if you use {DOT}, rather than
{KEYWORD}, thanks to designated initializers being in both Standard

[ Preprocessor ] [ Common ] Feature: Macros for identifying the wide and narrow execution string literal encoding

2020-10-08 Thread JeanHeyd Meneide via Gcc-patches
Dear GCC,

 This patch adds macros to the general preprocessor that allow
users to understand what the execution and wide execution charsets
are, which are used for "bark" and L"meow" literals in C-family
languages.

 The goal of this is to enable individuals in capable languages
like C and C++ to determine the encoding of string literals and,
hopefully, transcode those literals to other encodings. For example,
data stored in `char[]` on an IBM machine with EBCDIC can be
(losslessly, or with a compile-time warning) transcoded to UTF-8 at
constant-expression time in C++ with this patch, without having to use
a series of complicated architecture and platform definitions to
figure out what the encoding of string literals and wide character
literals might be.

 The names are meaningful because they are tied directly to iconv,
which means there is a strong reference between the name and the code
that encodes/decodes a proper sequence. Therefore, we just present the
names.

 Does this sound useful?

Sincerely,
JeanHeyd

Patch notes: the strings passed to the charset creation routines are
all static and/or allocated far at the beginning of the program and
never deallocated until the end of the invocation, so it seems safe to
just store a normal pointer to it.

2020-10-08  JeanHeyd "ThePhD" Meneide  

* gcc/c-family/c-cppbuiltin.c: Add predefined macro
definitions for charsets
* gcc/doc/cpp.texi: Document new predefined macro.
* gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c (new):
  New test for macro definitions to always exist.
* libcpp/include/cpplib.h: Add functions declarations for
  retrieving charset names
* libcpp/directives.c: Add function definitions to retrieve charset
  names.
* libcpp/internal.h: Add to/from name preservations
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 74ecca8de8e..8de25786592 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -866,6 +866,13 @@ c_cpp_builtins (cpp_reader *pfile)
 
   define_language_independent_builtin_macros (pfile);
 
+  /* encoding definitions used by users and libraries  */
+  builtin_define_with_value ("__GNUC_EXECUTION_CHARSET_NAME",
+cpp_get_narrow_charset_name (pfile), 1);
+  builtin_define_with_value ("__GNUC_WIDE_EXECUTION_CHARSET_NAME",
+cpp_get_wide_charset_name (pfile), 1);
+
+
   if (c_dialect_cxx ())
   {
 int major;
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 33f876ab706..55fa5739812 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -2451,6 +2451,13 @@ features are supported by GCC.
 @item __NO_MATH_ERRNO__
 This macro is defined if @option{-fno-math-errno} is used, or enabled
 by another option such as @option{-ffast-math} or by default.
+
+@item __GNUC_EXECUTION_CHARSET_NAME
+@itemx __GNUC_WIDE_EXECUTION_CHARSET_NAME
+These macros are defined to the name of the narrow and wide compile-time
+execution character set used.  It directly reflects the name passed to
+the options @option{-fexec-charset} and @option{-fwide-exec-charset},
+or the defaults documented for those options.  @xref{Invocation}.
 @end table
 
 @node System-specific Predefined Macros
diff --git a/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c 
b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
new file mode 100644
index 000..0f55e6915f4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
@@ -0,0 +1,10 @@
+/*
+   { dg-do compile }
+ */
+
+#if !defined(__GNUC_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for compile-time charset name is not 
present"
+#endif
+#if !defined(__GNUC_WIDE_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for wide compile-time charset name is 
not present"
+#endif
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 28b81c9c864..3e5578b1390 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -638,6 +638,9 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const 
char *from)
   char *pair;
   size_t i;
 
+  ret.to = to;
+  ret.from = from;
+
   if (!strcasecmp (to, from))
 {
   ret.func = convert_no_conversion;
diff --git a/libcpp/directives.c b/libcpp/directives.c
index f59718708e4..ad540872581 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -2571,6 +2571,20 @@ cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb)
   pfile->cb = *cb;
 }
 
+/* The narrow character set identifier.  */
+const char *
+cpp_get_narrow_charset_name (cpp_reader *pfile)
+{
+  return pfile->narrow_cset_desc.to;
+}
+
+/* The wide character set identifier.  */
+const char *
+cpp_get_wide_charset_name (cpp_reader *pfile)
+{
+  return pfile->wide_cset_desc.to;
+}
+
 /* The dependencies structure.  (Creates one if it hasn't already been.)  */
 class mkdeps *
 cpp_get_deps (cpp_reader *pfile)
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 8e398863cf6..69a5042d0bf

Re: [ Preprocessor ] [ Common ] Feature: Macros for identifying the wide and narrow execution string literal encoding

2020-10-08 Thread JeanHeyd Meneide via Gcc-patches
Dear Joseph,

On Thu, Oct 8, 2020 at 1:36 PM Joseph Myers  wrote:
>
> This documentation doesn't seem sufficient to use the macros.  Do they
> expand to (narrow) string literals?  To an unquoted sequence of
> characters?  I think from the implementation that the answer is strings
> (so, in particular, not usable for testing anything in #if conditionals),
> but the documentation ought to say so.  The test ought to verify the form
> of the expansion as well (even if it can't do anything useful at execution
> time, because if you make the macros reflect the command-line options they
> are character set names that are meaningful on the host, and any
> conversion functionality on the target may not use the same names as the
> host).

 You're right; sorry about that, I should have been more thorough!
I thought about adding a test to check the name itself (e.g, for
"UTF-8"), but that might make tests fail on platforms where the
default SOURCE_CHARSET from the dev files is not, in fact, UTF-8. I
could also try to pass some options but then I'd have to guarantee
that the encoding was available on all testable platforms, too...!

In the end, for the tests, I just initialize two "const char[]"
directly from the macro expansions to make sure we are getting
strings. It seems to work okay. Attached is the revised patch with
better docs and test!

Sincerely,
JeanHeyd

2020-10-08  JeanHeyd "ThePhD" Meneide  

* gcc/c-family/c-cppbuiltin.c: Add predefined macro
definitions for charsets
* gcc/doc/cpp.texi: Document new predefined macro.
* gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c (new):
  New test for macro definitions to always exist.
* libcpp/include/cpplib.h: Add functions declarations for
  retrieving charset names
* libcpp/directives.c: Add function definitions to retrieve charset
  names.
* libcpp/internal.h: Add to/from name preservations
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 74ecca8de8e..8de25786592 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -866,6 +866,13 @@ c_cpp_builtins (cpp_reader *pfile)
 
   define_language_independent_builtin_macros (pfile);
 
+  /* encoding definitions used by users and libraries  */
+  builtin_define_with_value ("__GNUC_EXECUTION_CHARSET_NAME",
+cpp_get_narrow_charset_name (pfile), 1);
+  builtin_define_with_value ("__GNUC_WIDE_EXECUTION_CHARSET_NAME",
+cpp_get_wide_charset_name (pfile), 1);
+
+
   if (c_dialect_cxx ())
   {
 int major;
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 33f876ab706..90f1162add1 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -2451,6 +2451,15 @@ features are supported by GCC.
 @item __NO_MATH_ERRNO__
 This macro is defined if @option{-fno-math-errno} is used, or enabled
 by another option such as @option{-ffast-math} or by default.
+
+@item __GNUC_EXECUTION_CHARSET_NAME
+@itemx __GNUC_WIDE_EXECUTION_CHARSET_NAME
+These macros are defined to expand to a narrow string literal of
+the name of the narrow and wide compile-time execution character
+set used.  It directly reflects the name passed to the options
+@option{-fexec-charset} and @option{-fwide-exec-charset}, or the defaults
+documented for those options (that is, it can expand to something like 
+@code{"UTF-8"}).  @xref{Invocation}.
 @end table
 
 @node System-specific Predefined Macros
diff --git a/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c 
b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
new file mode 100644
index 000..d5440f8a61e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
@@ -0,0 +1,13 @@
+/*
+   { dg-do compile }
+ */
+
+#if !defined(__GNUC_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for comple-time charset name is not 
present"
+#endif
+#if !defined(__GNUC_WIDE_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for wide comple-time charset name is not 
present"
+#endif
+
+const char narrow_name[] = __GNUC_EXECUTION_CHARSET_NAME;
+const char wide_name[] = __GNUC_WIDE_EXECUTION_CHARSET_NAME;
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 28b81c9c864..3e5578b1390 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -638,6 +638,9 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const 
char *from)
   char *pair;
   size_t i;
 
+  ret.to = to;
+  ret.from = from;
+
   if (!strcasecmp (to, from))
 {
   ret.func = convert_no_conversion;
diff --git a/libcpp/directives.c b/libcpp/directives.c
index f59718708e4..ad540872581 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -2571,6 +2571,20 @@ cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb)
   pfile->cb = *cb;
 }
 
+/* The narrow character set identifier.  */
+const char *
+cpp_get_narrow_charset_name (cpp_reader *pfile)
+{
+  return pfile->narrow_cset_desc.to;
+}
+
+/* The wide character set identifier.  */
+const ch

Re: [ Preprocessor ] [ Common ] Feature: Macros for identifying the wide and narrow execution string literal encoding

2020-10-09 Thread JeanHeyd Meneide via Gcc-patches
Hello,

> Typo:  comple-time
>
> >2020-10-08  JeanHeyd "ThePhD" Meneide  
> >
> >* gcc/c-family/c-cppbuiltin.c: Add predefined macro
> >definitions for charsets
>
> I think you should put the macro names in braces after the filename and drop 
> the trailing "for charsets".

 Can do!

>
> >* gcc/doc/cpp.texi: Document new predefined macro.
> >* gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c (new):
>
> I think you should drop "(new)" above.
> thanks,

 I saw that in previous changelogs, but I can change it! Fixed up
the typos, too.

Sincerely,
JeanHeyd

2020-10-09  JeanHeyd "ThePhD" Meneide  

* gcc/c-family/c-cppbuiltin.c: Add predefined
  {__GNUC_EXECUTION_CHARSET_NAME} and
  {__GNUC_WIDE_EXECUTION_CHARSET_NAME} macros
* gcc/doc/cpp.texi: Document above new predefined macros
* gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c:
  New test for macro definitions to always exist and be strings
* libcpp/include/cpplib.h: Add functions declarations for
  retrieving charset names
* libcpp/directives.c: Add function definitions to retrieve charset
  names
* libcpp/internal.h: Add to/from name preservations
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 74ecca8de8e..8de25786592 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -866,6 +866,13 @@ c_cpp_builtins (cpp_reader *pfile)
 
   define_language_independent_builtin_macros (pfile);
 
+  /* encoding definitions used by users and libraries  */
+  builtin_define_with_value ("__GNUC_EXECUTION_CHARSET_NAME",
+cpp_get_narrow_charset_name (pfile), 1);
+  builtin_define_with_value ("__GNUC_WIDE_EXECUTION_CHARSET_NAME",
+cpp_get_wide_charset_name (pfile), 1);
+
+
   if (c_dialect_cxx ())
   {
 int major;
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 33f876ab706..90f1162add1 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -2451,6 +2451,15 @@ features are supported by GCC.
 @item __NO_MATH_ERRNO__
 This macro is defined if @option{-fno-math-errno} is used, or enabled
 by another option such as @option{-ffast-math} or by default.
+
+@item __GNUC_EXECUTION_CHARSET_NAME
+@itemx __GNUC_WIDE_EXECUTION_CHARSET_NAME
+These macros are defined to expand to a narrow string literal of
+the name of the narrow and wide compile-time execution character
+set used.  It directly reflects the name passed to the options
+@option{-fexec-charset} and @option{-fwide-exec-charset}, or the defaults
+documented for those options (that is, it can expand to something like 
+@code{"UTF-8"}).  @xref{Invocation}.
 @end table
 
 @node System-specific Predefined Macros
diff --git a/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c 
b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
new file mode 100644
index 000..d5440f8a61e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c
@@ -0,0 +1,13 @@
+/*
+   { dg-do compile }
+ */
+
+#if !defined(__GNUC_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for compile-time charset name is not 
present"
+#endif
+#if !defined(__GNUC_WIDE_EXECUTION_CHARSET_NAME)
+#error "Required implementation macro for wide compile-time charset name is 
not present"
+#endif
+
+const char narrow_name[] = __GNUC_EXECUTION_CHARSET_NAME;
+const char wide_name[] = __GNUC_WIDE_EXECUTION_CHARSET_NAME;
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 28b81c9c864..3e5578b1390 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -638,6 +638,9 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const 
char *from)
   char *pair;
   size_t i;
 
+  ret.to = to;
+  ret.from = from;
+
   if (!strcasecmp (to, from))
 {
   ret.func = convert_no_conversion;
diff --git a/libcpp/directives.c b/libcpp/directives.c
index f59718708e4..ad540872581 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -2571,6 +2571,20 @@ cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb)
   pfile->cb = *cb;
 }
 
+/* The narrow character set identifier.  */
+const char *
+cpp_get_narrow_charset_name (cpp_reader *pfile)
+{
+  return pfile->narrow_cset_desc.to;
+}
+
+/* The wide character set identifier.  */
+const char *
+cpp_get_wide_charset_name (cpp_reader *pfile)
+{
+  return pfile->wide_cset_desc.to;
+}
+
 /* The dependencies structure.  (Creates one if it hasn't already been.)  */
 class mkdeps *
 cpp_get_deps (cpp_reader *pfile)
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 8e398863cf6..69a5042d0bf 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -971,6 +971,11 @@ extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) 
ATTRIBUTE_PURE;
 extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
 extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE;
 
+/* Call these to get name data about the various compile-time
+   charsets.  */
+extern const c

Re: [committed] libstdc++: Make __int128 meet integer-class requirements [PR 96042]

2020-08-22 Thread JeanHeyd Meneide via Gcc-patches
On Sat, Aug 22, 2020 at 8:14 AM Jonathan Wakely via Gcc-patches
 wrote:
> I really wish WG14 would just fix the intmax_t mess so we can make
> them integral types unconditionally.

We're trying, but we're struggling to reach a good consensus. Almost
nobody's fully agreeing on one /particular/ solution (there's roughly
3 ideas of what to do).

But the papers are coming in and it's on our radar so maybe we can fix
it for C2x and then pass the solution on to WG21!


Re: [ Preprocessor ] [ Common ] Feature: Macros for identifying the wide and narrow execution string literal encoding

2020-11-23 Thread JeanHeyd Meneide via Gcc-patches
Dear Jeff,

On Mon, Nov 23, 2020 at 3:02 PM Jeff Law  wrote:
>
> You use a getter function to retrieve the value of ret.to, which is
> fine.  Is there a specific reason why you're not using a setter function
> to save the value?

 I did this because I have access to ret.to in the libcpp
functions! Outside, the structure of that type is unknown and only a
pointer, so it needs the getter function.

Sincerely,
JeanHeyd


Re: [ Preprocessor ] [ Common ] Feature: Macros for identifying the wide and narrow execution string literal encoding

2020-10-29 Thread JeanHeyd Meneide via Gcc-patches
(Very very gentle ping, just to make sure it's still on anyone's radar...!)

On Fri, Oct 9, 2020 at 8:39 AM JeanHeyd Meneide  wrote:
>
> Hello,
>
> > Typo:  comple-time
> >
> > >2020-10-08  JeanHeyd "ThePhD" Meneide  
> > >
> > >* gcc/c-family/c-cppbuiltin.c: Add predefined macro
> > >definitions for charsets
> >
> > I think you should put the macro names in braces after the filename and 
> > drop the trailing "for charsets".
>
>  Can do!
>
> >
> > >* gcc/doc/cpp.texi: Document new predefined macro.
> > >* gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c (new):
> >
> > I think you should drop "(new)" above.
> > thanks,
>
>  I saw that in previous changelogs, but I can change it! Fixed up
> the typos, too.
>
> Sincerely,
> JeanHeyd
>
> 2020-10-09  JeanHeyd "ThePhD" Meneide  
>
> * gcc/c-family/c-cppbuiltin.c: Add predefined
>   {__GNUC_EXECUTION_CHARSET_NAME} and
>   {__GNUC_WIDE_EXECUTION_CHARSET_NAME} macros
> * gcc/doc/cpp.texi: Document above new predefined macros
> * gcc/testsuite/c-c++-common/cpp/wide-narrow-predef-macros.c:
>   New test for macro definitions to always exist and be strings
> * libcpp/include/cpplib.h: Add functions declarations for
>   retrieving charset names
> * libcpp/directives.c: Add function definitions to retrieve charset
>   names
> * libcpp/internal.h: Add to/from name preservations