From: Jakub Jelinek Date: Mon, 17 Nov 2025 08:44:05 +0000 (+0100) Subject: GCC, meet C++20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4a37c4b8caf7f1765d0774f87e5e97079aa09b6;p=thirdparty%2Fgcc.git GCC, meet C++20 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 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" "). --- diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 6851c60fd76..4a9c8564c99 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -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); diff --git a/gcc/common/config/i386/i386-cpuinfo.h b/gcc/common/config/i386/i386-cpuinfo.h index e5323f10327..63357da9bd4 100644 --- a/gcc/common/config/i386/i386-cpuinfo.h +++ b/gcc/common/config/i386/i386-cpuinfo.h @@ -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) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index f987f464023..19139ccb955 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -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; diff --git a/gcc/gimple.h b/gcc/gimple.h index 9bd3f8c0197..b421850625e 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -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)); } diff --git a/gcc/ipa-modref-tree.cc b/gcc/ipa-modref-tree.cc index 1a7e204d71e..8bb8471f4c4 100644 --- a/gcc/ipa-modref-tree.cc +++ b/gcc/ipa-modref-tree.cc @@ -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; diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h index 35410dea08c..b78741cae35 100644 --- a/gcc/ipa-modref-tree.h +++ b/gcc/ipa-modref-tree.h @@ -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. */ diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h index a398f4394be..c7c6c8fbf06 100644 --- a/gcc/lto-streamer.h +++ b/gcc/lto-streamer.h @@ -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; } diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc index e339b3a5b37..d53c472b0cb 100644 --- a/gcc/tree-complex.cc +++ b/gcc/tree-complex.cc @@ -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); diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 33a6a78f00d..88627ac9381 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -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 diff --git a/libcody/cody.hh b/libcody/cody.hh index 789ce9e70b7..506b903987c 100644 --- a/libcody/cody.hh +++ b/libcody/cody.hh @@ -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: