]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
GCC, meet C++20
authorJakub Jelinek <jakub@redhat.com>
Mon, 17 Nov 2025 08:44:05 +0000 (09:44 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 17 Nov 2025 08:44:05 +0000 (09:44 +0100)
I've tried to test a patch to switch -std=gnu++17 C++ default
to -std=gnu++20 (will post momentarily), but ran into various problems
during GCC bootstraps, our codebase isn't fully C++20 ready.

The most common problems are arithmetic or bitwise operations
between enumerators of different enum types (or between enumerator
and floating point in the testsuite), ambiguous overloaded
operator == because of forgotten const qualification of const inside
of the argument and then libcody being largely stuck in C++ and incompatible
with C++20 which introduced char8_t type and uses it for u8 literals.

The following patch fixes various issues I've run into, for libcody
this patch just makes sure code including cody.hh can be compiled
with -std=gnu++20, libcody itself I have a tweak in the other patch.

Nothing in this patch will make the code invalid for C++14.

2025-11-17  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree-core.h (enum built_in_function): Avoid arithmetics or
bitwise operations between enumerators from different enums.
* lto-streamer.h (lto_tag_is_gimple_code_p): Likewise.
* gimple.h (gimple_omp_atomic_set_memory_order): Likewise.
* common/config/i386/i386-cpuinfo.h (M_CPU_SUBTYPE_START,
M_CPU_TYPE): Likewise.
* tree-complex.cc (expand_complex_libcall): Likewise.
* ipa-modref-tree.h (modref_access_node::operator ==): Change
argument type from modref_access_node & to
const modref_access_node &.
* ipa-modref-tree.cc (modref_access_node::operator ==): Likewise.
gcc/cobol/
* symbols.cc (symbol_table_init): Avoid arithmetics or
bitwise operations between enumerators from different enums.
gcc/fortran/
* parse.cc (gfc_parse_file): Avoid arithmetics or
bitwise operations between enumerators from different enums.
libcody/
* cody.hh (MessageBuffer::Space): For C++14 or newer use
(char) u8' ' instead of Detail::S2C(u8" ").

gcc/cobol/symbols.cc
gcc/common/config/i386/i386-cpuinfo.h
gcc/fortran/parse.cc
gcc/gimple.h
gcc/ipa-modref-tree.cc
gcc/ipa-modref-tree.h
gcc/lto-streamer.h
gcc/tree-complex.cc
gcc/tree-core.h
libcody/cody.hh

index 6851c60fd76d3d232c81ca442ed2e4f31e1f3c24..4a9c8564c9962c24fc08470d0b6dde7531181864 100644 (file)
@@ -2270,20 +2270,20 @@ symbol_table_init(void) {
 
   // These should match the definitions in libgcobol/constants.cc
   static cbl_field_t constants[] = {
-    { FldAlphanumeric, space_value_e | constq | register_e,
+    { FldAlphanumeric, space_value_e | int(constq) | register_e,
       {1,1,0,0, " \0\xFF"}, 0, "SPACE" },
-    { FldAlphanumeric, space_value_e | constq | register_e,
+    { FldAlphanumeric, space_value_e | int(constq) | register_e,
       {1,1,0,0, " \0\xFF"}, 0, "SPACES" },
-    { FldAlphanumeric, low_value_e | constq | register_e,
+    { FldAlphanumeric, low_value_e | int(constq) | register_e,
       {1,1,0,0, "L\0\xFF"}, 0, "LOW_VALUES" },
-    { FldAlphanumeric, zero_value_e | constq | register_e,
+    { FldAlphanumeric, zero_value_e | int(constq) | register_e,
       {1,1,0,0, "0"}, 0, "ZEROS" },
-    { FldAlphanumeric, high_value_e | constq | register_e,
+    { FldAlphanumeric, high_value_e | int(constq) | register_e,
       {1,1,0,0, "H\0\xFF"}, 0, "HIGH_VALUES" },
     // IBM standard: QUOTE is a double-quote unless APOST compiler option
-    { FldAlphanumeric, quote_value_e | constq | register_e ,
+    { FldAlphanumeric, quote_value_e | int(constq) | register_e ,
       {1,1,0,0, "\"\0\xFF"}, 0, "QUOTES" },
-    { FldPointer, constq | register_e ,
+    { FldPointer, int(constq) | register_e ,
       {8,8,0,0, zeroes_for_null_pointer}, 0, "NULLS" },
     // IBM defines TALLY
     // 01  TALLY GLOBAL PICTURE 9(5) USAGE BINARY VALUE ZERO.
@@ -2421,9 +2421,9 @@ symbol_table_init(void) {
     { FldNumericBin5,    signable_e|register_e, {2,2,4,0, NULL}, 0, "RETURN-CODE" },
     { FldNumericBin5,    register_e, {2,2,4,0, NULL}, 0, "LINAGE-COUNTER" },
     { FldLiteralA,        register_e, {0,0,0,0, "/dev/stdin"}, 0, "_dev_stdin" },
-    { FldLiteralA, constq|register_e, {0,0,0,0, "/dev/stdout"}, 0, "_dev_stdout" },
-    { FldLiteralA, constq|register_e, {0,0,0,0, "/dev/stderr"}, 0, "_dev_stderr" },
-    { FldLiteralA, constq|register_e, {0,0,0,0, "/dev/null"},   0, "_dev_null" },
+    { FldLiteralA, int(constq)|register_e, {0,0,0,0, "/dev/stdout"}, 0, "_dev_stdout" },
+    { FldLiteralA, int(constq)|register_e, {0,0,0,0, "/dev/stderr"}, 0, "_dev_stderr" },
+    { FldLiteralA, int(constq)|register_e, {0,0,0,0, "/dev/null"},   0, "_dev_null" },
   };
 
   assert(table.nelem + COUNT_OF(special_registers) < table.capacity);
index e5323f103278b352be2b8f00f878d4fabc09b75e..63357da9bd401ca4369653136e8fcb9a1e3b82b4 100644 (file)
@@ -285,7 +285,7 @@ enum processor_features
 
 #define M_CPU_TYPE_START (BUILTIN_VENDOR_MAX)
 #define M_CPU_SUBTYPE_START \
-  (M_CPU_TYPE_START + BUILTIN_CPU_TYPE_MAX)
+  (M_CPU_TYPE_START + int (BUILTIN_CPU_TYPE_MAX))
 #define M_VENDOR(a) (a)
-#define M_CPU_TYPE(a) (M_CPU_TYPE_START + a)
+#define M_CPU_TYPE(a) (M_CPU_TYPE_START + int (a))
 #define M_CPU_SUBTYPE(a) (M_CPU_SUBTYPE_START + a)
index f987f4640233cc2cd7f4b403c9e51f972be67bc2..19139ccb9559c668ad9d1b0c07d257475c1e3ac4 100644 (file)
@@ -7793,45 +7793,53 @@ done:
     {
     case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST:
       omp_requires_mask
-       = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_SEQ_CST);
+       = (enum omp_requires) (omp_requires_mask
+                              | int (OMP_MEMORY_ORDER_SEQ_CST));
       break;
     case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL:
       omp_requires_mask
-       = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQ_REL);
+       = (enum omp_requires) (omp_requires_mask
+                              | int (OMP_MEMORY_ORDER_ACQ_REL));
       break;
     case OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE:
       omp_requires_mask
-       = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_ACQUIRE);
+       = (enum omp_requires) (omp_requires_mask
+                              | int (OMP_MEMORY_ORDER_ACQUIRE));
       break;
     case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED:
       omp_requires_mask
-       = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELAXED);
+       = (enum omp_requires) (omp_requires_mask
+                              | int (OMP_MEMORY_ORDER_RELAXED));
       break;
     case OMP_REQ_ATOMIC_MEM_ORDER_RELEASE:
       omp_requires_mask
-       = (enum omp_requires) (omp_requires_mask | OMP_MEMORY_ORDER_RELEASE);
+       = (enum omp_requires) (omp_requires_mask
+                              | int (OMP_MEMORY_ORDER_RELEASE));
       break;
     }
 
   if (omp_target_seen)
     omp_requires_mask = (enum omp_requires) (omp_requires_mask
-                                            | OMP_REQUIRES_TARGET_USED);
+                                            | int (OMP_REQUIRES_TARGET_USED));
   if (omp_requires & OMP_REQ_REVERSE_OFFLOAD)
-    omp_requires_mask = (enum omp_requires) (omp_requires_mask
-                                            | OMP_REQUIRES_REVERSE_OFFLOAD);
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask
+                            | int (OMP_REQUIRES_REVERSE_OFFLOAD));
   if (omp_requires & OMP_REQ_UNIFIED_ADDRESS)
-    omp_requires_mask = (enum omp_requires) (omp_requires_mask
-                                            | OMP_REQUIRES_UNIFIED_ADDRESS);
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask
+                            | int (OMP_REQUIRES_UNIFIED_ADDRESS));
   if (omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
     omp_requires_mask
-         = (enum omp_requires) (omp_requires_mask
-                                | OMP_REQUIRES_UNIFIED_SHARED_MEMORY);
+      = (enum omp_requires) (omp_requires_mask
+                            | int (OMP_REQUIRES_UNIFIED_SHARED_MEMORY));
   if (omp_requires & OMP_REQ_SELF_MAPS)
     omp_requires_mask
-         = (enum omp_requires) (omp_requires_mask | OMP_REQUIRES_SELF_MAPS);
+      = (enum omp_requires) (omp_requires_mask | int (OMP_REQUIRES_SELF_MAPS));
   if (omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
-    omp_requires_mask = (enum omp_requires) (omp_requires_mask
-                                            | OMP_REQUIRES_DYNAMIC_ALLOCATORS);
+    omp_requires_mask
+      = (enum omp_requires) (omp_requires_mask
+                            | int (OMP_REQUIRES_DYNAMIC_ALLOCATORS));
   /* Do the parse tree dump.  */
   gfc_current_ns = flag_dump_fortran_original ? gfc_global_ns_list : NULL;
 
index 9bd3f8c019704db4948d4f82d8d456dc17da5602..b421850625e036a4a55fd618d272c946c1ce755a 100644 (file)
@@ -2559,7 +2559,7 @@ gimple_omp_atomic_set_memory_order (gimple *g, enum omp_memory_order mo)
   if (gimple_code (g) != GIMPLE_OMP_ATOMIC_LOAD)
     GIMPLE_CHECK (g, GIMPLE_OMP_ATOMIC_STORE);
   g->subcode = ((g->subcode & ~GF_OMP_ATOMIC_MEMORY_ORDER)
-               | (mo & GF_OMP_ATOMIC_MEMORY_ORDER));
+               | (int (mo) & GF_OMP_ATOMIC_MEMORY_ORDER));
 }
 
 
index 1a7e204d71e2b473560ea826aeea7e6649e2b3aa..8bb8471f4c4dc0f6de311d6eb60d19dd837eb611 100644 (file)
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Return true if both accesses are the same.  */
 bool
-modref_access_node::operator == (modref_access_node &a) const
+modref_access_node::operator == (const modref_access_node &a) const
 {
   if (parm_index != a.parm_index)
     return false;
index 35410dea08cd51e6c05bf8ea3940501be62d3121..b78741cae35a1d1046bf842e61db1360c9042f0a 100644 (file)
@@ -96,7 +96,7 @@ struct GTY(()) modref_access_node
   /* Dump range to debug OUT.  */
   void dump (FILE *out);
   /* Return true if both accesses are the same.  */
-  bool operator == (modref_access_node &a) const;
+  bool operator == (const modref_access_node &a) const;
   /* Return true if range info is useful.  */
   bool range_info_useful_p () const;
   /* Return tree corresponding to parameter of the range in STMT.  */
index a398f4394be3474894ac629afcf4a5d831bc1321..c7c6c8fbf0640b60873b74fbbc2a7c7a7ad4564a 100644 (file)
@@ -990,7 +990,7 @@ lto_tag_is_gimple_code_p (enum LTO_tags tag)
 {
   return (unsigned) tag >= LTO_first_gimple_tag
         && (unsigned) tag
-           < LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE;
+           < (unsigned) LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE;
 }
 
 
index e339b3a5b377f30fe7debc32376d2ce0412246e1..d53c472b0cb879c733c053ed832ef3a1a9453f40 100644 (file)
@@ -1042,10 +1042,10 @@ expand_complex_libcall (gimple_stmt_iterator *gsi, tree type, tree ar, tree ai,
 
   if (code == MULT_EXPR)
     bcode = ((enum built_in_function)
-            (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
+            (BUILT_IN_COMPLEX_MUL_MIN + (mode - MIN_MODE_COMPLEX_FLOAT)));
   else if (code == RDIV_EXPR)
     bcode = ((enum built_in_function)
-            (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
+            (BUILT_IN_COMPLEX_DIV_MIN + (mode - MIN_MODE_COMPLEX_FLOAT)));
   else
     gcc_unreachable ();
   fn = builtin_decl_explicit (bcode);
index 33a6a78f00db2af21a82bdfccd158eaf25edd3e1..88627ac938161b5d930d99fa6fa24d8491aa1a28 100644 (file)
@@ -190,14 +190,12 @@ enum built_in_function {
   BUILT_IN_COMPLEX_MUL_MIN,
   BUILT_IN_COMPLEX_MUL_MAX
     = BUILT_IN_COMPLEX_MUL_MIN
-      + MAX_MODE_COMPLEX_FLOAT
-      - MIN_MODE_COMPLEX_FLOAT,
+      + (MAX_MODE_COMPLEX_FLOAT - MIN_MODE_COMPLEX_FLOAT),
 
   BUILT_IN_COMPLEX_DIV_MIN,
   BUILT_IN_COMPLEX_DIV_MAX
     = BUILT_IN_COMPLEX_DIV_MIN
-      + MAX_MODE_COMPLEX_FLOAT
-      - MIN_MODE_COMPLEX_FLOAT,
+      + (MAX_MODE_COMPLEX_FLOAT - MIN_MODE_COMPLEX_FLOAT),
 
   /* Upper bound on non-language-specific builtins.  */
   END_BUILTINS
index 789ce9e70b752e2eb10d1b4419e0d4140f6beb6a..506b903987c03f2e909369e30db5b506f424eb33 100644 (file)
@@ -110,7 +110,11 @@ public:
   /// Add whitespace word separator.  Multiple adjacent whitespace is fine.
   void Space ()
   {
+#if __cpp_unicode_characters >= 201411
+    Append ((char) u8' ');
+#else
     Append (Detail::S2C(u8" "));
+#endif
   }
 
 public: