git: eb5e0517d2a6 - main - lang/gcc10: fix build with clang 17

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Fri, 15 Dec 2023 20:37:51 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/ports/commit/?id=eb5e0517d2a6e25d43fd03786f526e9043543b47

commit eb5e0517d2a6e25d43fd03786f526e9043543b47
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-15 20:15:59 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-12-15 20:37:00 +0000

    lang/gcc10: fix build with clang 17
    
    When building lang/gcc10 with recent clang versions, which default to
    C++17, the following errors are produced:
    
      cfns.gperf:35:18: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
         35 | libc_name::hash (register const char *str, register unsigned int len)
            |                  ^~~~~~~~
      cfns.gperf:35:44: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
         35 | libc_name::hash (register const char *str, register unsigned int len)
            |                                            ^~~~~~~~
      ...many more of these...
    
    Upstream fixed this in
    https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=642dc602f89b2c11d5d833a52f37b04427a27cab,
    so apply it.
---
 .../patch-base_containers_checked__iterators.h     |  75 ++++++++++++++
 lang/gcc10/files/patch-gcc_cp_cfns.h               | 111 +++++++++++++++++++++
 2 files changed, 186 insertions(+)

diff --git a/devel/electron25/files/patch-base_containers_checked__iterators.h b/devel/electron25/files/patch-base_containers_checked__iterators.h
new file mode 100644
index 000000000000..a5ad942a78cf
--- /dev/null
+++ b/devel/electron25/files/patch-base_containers_checked__iterators.h
@@ -0,0 +1,75 @@
+--- base/containers/checked_iterators.h.orig	2023-08-12 07:07:10 UTC
++++ base/containers/checked_iterators.h
+@@ -24,6 +24,9 @@ class CheckedContiguousIterator {
+   using pointer = T*;
+   using reference = T&;
+   using iterator_category = std::random_access_iterator_tag;
++#if __cplusplus >= 202002L
++  using iterator_concept = std::contiguous_iterator_tag;
++#endif
+ 
+   // Required for converting constructor below.
+   template <typename U>
+@@ -31,10 +34,8 @@ class CheckedContiguousIterator {
+ 
+   // Required for certain libc++ algorithm optimizations that are not available
+   // for NaCl.
+-#if defined(_LIBCPP_VERSION) && !BUILDFLAG(IS_NACL)
+   template <typename Ptr>
+   friend struct std::pointer_traits;
+-#endif
+ 
+   constexpr CheckedContiguousIterator() = default;
+ 
+@@ -224,7 +225,6 @@ using CheckedContiguousConstIterator = CheckedContiguo
+ 
+ }  // namespace base
+ 
+-#if defined(_LIBCPP_VERSION) && !BUILDFLAG(IS_NACL)
+ // Specialize both std::__is_cpp17_contiguous_iterator and std::pointer_traits
+ // for CCI in case we compile with libc++ outside of NaCl. The former is
+ // required to enable certain algorithm optimizations (e.g. std::copy can be a
+@@ -242,13 +242,35 @@ using CheckedContiguousConstIterator = CheckedContiguo
+ // [1] https://wg21.link/iterator.concept.contiguous
+ // [2] https://wg21.link/std.iterator.tags
+ // [3] https://wg21.link/pointer.traits.optmem
+-namespace std {
+ 
++#if defined(_LIBCPP_VERSION)
++
++// TODO(crbug.com/1284275): Remove when C++20 is on by default, as the use
++// of `iterator_concept` above should suffice.
++_LIBCPP_BEGIN_NAMESPACE_STD
++
++// TODO(crbug.com/1449299): https://reviews.llvm.org/D150801 renamed this from
++// `__is_cpp17_contiguous_iterator` to `__libcpp_is_contiguous_iterator`. Clean
++// up the old spelling after libc++ rolls.
+ template <typename T>
++struct __is_cpp17_contiguous_iterator;
++template <typename T>
+ struct __is_cpp17_contiguous_iterator<::base::CheckedContiguousIterator<T>>
+     : true_type {};
+ 
+ template <typename T>
++struct __libcpp_is_contiguous_iterator;
++template <typename T>
++struct __libcpp_is_contiguous_iterator<::base::CheckedContiguousIterator<T>>
++    : true_type {};
++
++_LIBCPP_END_NAMESPACE_STD
++
++#endif
++
++namespace std {
++
++template <typename T>
+ struct pointer_traits<::base::CheckedContiguousIterator<T>> {
+   using pointer = ::base::CheckedContiguousIterator<T>;
+   using element_type = T;
+@@ -267,6 +289,5 @@ struct pointer_traits<::base::CheckedContiguousIterato
+ };
+ 
+ }  // namespace std
+-#endif
+ 
+ #endif  // BASE_CONTAINERS_CHECKED_ITERATORS_H_
diff --git a/lang/gcc10/files/patch-gcc_cp_cfns.h b/lang/gcc10/files/patch-gcc_cp_cfns.h
new file mode 100644
index 000000000000..c542619ec0eb
--- /dev/null
+++ b/lang/gcc10/files/patch-gcc_cp_cfns.h
@@ -0,0 +1,111 @@
+commit 642dc602f89b2c11d5d833a52f37b04427a27cab
+Author: Marek Polacek <polacek@redhat.com>
+Date:   2020-05-15T23:54:05+02:00
+
+    c++: Regenerate cp/cfns.h.
+    
+    Current cfns.h includes register-qualified variables and that wouldn't
+    play well when bootstrapping with GCC that uses the C++17 dialect,
+    because 'register' was removed in C++17.  Regenerating it using the
+    command specified in cfns.h luckily cleaned this up.
+    
+            * cfns.h: Regenerated.
+
+--- gcc/cp/cfns.h.orig	2023-07-07 07:08:19 UTC
++++ gcc/cp/cfns.h
+@@ -1,4 +1,4 @@
+-/* C++ code produced by gperf version 3.0.4 */
++/* C++ code produced by gperf version 3.1 */
+ /* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L C++ --output-file cfns.h cfns.gperf  */
+ 
+ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+@@ -25,7 +25,7 @@
+       && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+       && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+ /* The character set is not based on ISO-646.  */
+-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
++#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
+ #endif
+ 
+ #line 4 "cfns.gperf"
+@@ -54,13 +54,13 @@ class libc_name (private)
+ class libc_name
+ {
+ private:
+-  static inline unsigned int hash (const char *str, unsigned int len);
++  static inline unsigned int hash (const char *str, size_t len);
+ public:
+-  static const struct libc_name_struct *libc_name_p (const char *str, unsigned int len);
++  static const struct libc_name_struct *libc_name_p (const char *str, size_t len);
+ };
+ 
+ inline unsigned int
+-libc_name::hash (register const char *str, register unsigned int len)
++libc_name::hash (const char *str, size_t len)
+ {
+   static const unsigned short asso_values[] =
+     {
+@@ -91,34 +91,34 @@ libc_name::hash (register const char *str, register un
+       1488, 1488, 1488, 1488, 1488, 1488, 1488, 1488, 1488, 1488,
+       1488, 1488, 1488, 1488, 1488, 1488, 1488
+     };
+-  register int hval = len;
++  unsigned int hval = len;
+ 
+   switch (hval)
+     {
+       default:
+-        hval += asso_values[(unsigned char)str[5]+1];
++        hval += asso_values[static_cast<unsigned char>(str[5]+1)];
+       /*FALLTHROUGH*/
+       case 5:
+-        hval += asso_values[(unsigned char)str[4]];
++        hval += asso_values[static_cast<unsigned char>(str[4])];
+       /*FALLTHROUGH*/
+       case 4:
+-        hval += asso_values[(unsigned char)str[3]];
++        hval += asso_values[static_cast<unsigned char>(str[3])];
+       /*FALLTHROUGH*/
+       case 3:
+-        hval += asso_values[(unsigned char)str[2]];
++        hval += asso_values[static_cast<unsigned char>(str[2])];
+       /*FALLTHROUGH*/
+       case 2:
+-        hval += asso_values[(unsigned char)str[1]+1];
++        hval += asso_values[static_cast<unsigned char>(str[1]+1)];
+       /*FALLTHROUGH*/
+       case 1:
+-        hval += asso_values[(unsigned char)str[0]];
++        hval += asso_values[static_cast<unsigned char>(str[0])];
+         break;
+     }
+-  return hval + asso_values[(unsigned char)str[len - 1]];
++  return hval + asso_values[static_cast<unsigned char>(str[len - 1])];
+ }
+ 
+ const struct libc_name_struct *
+-libc_name::libc_name_p (register const char *str, register unsigned int len)
++libc_name::libc_name_p (const char *str, size_t len)
+ {
+   enum
+     {
+@@ -1116,15 +1116,15 @@ libc_name::libc_name_p (register const char *str, regi
+ 
+   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+     {
+-      register int key = hash (str, len);
++      unsigned int key = hash (str, len);
+ 
+-      if (key <= MAX_HASH_VALUE && key >= 0)
++      if (key <= MAX_HASH_VALUE)
+         {
+-          register int index = lookup[key];
++          int index = lookup[key];
+ 
+           if (index >= 0)
+             {
+-              register const char *s = wordlist[index].name;
++              const char *s = wordlist[index].name;
+ 
+               if (*str == *s && !strcmp (str + 1, s + 1))
+                 return &wordlist[index];