aboutsummaryrefslogtreecommitdiff
path: root/libcpp/internal.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-10-07 21:25:22 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2024-10-07 21:25:22 +0200
commite4c0595ec4ed3cd2f6fb471081a9d2d3960e1672 (patch)
tree70409b86e70deccbb9c63742ad858ecf19e0fe5e /libcpp/internal.h
parentc0002a675a92e76d2f326bf4629d8e4127a0c9da (diff)
downloadgcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.zip
gcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.tar.gz
gcc-e4c0595ec4ed3cd2f6fb471081a9d2d3960e1672.tar.bz2
libcpp: Use constexpr for _cpp_trigraph_map initialization for C++14
The _cpp_trigraph_map initialization used to be done for C99+ using designated initializers, but can't be done that way for C++ because the designated initializer support in C++ as array designators are just an extension there and don't allow skipping anything nor going backwards. But, we can get the same effect using C++14 constexpr constructor. With the following patch we get rid of the runtime initialization and the array can be in .rodata. 2024-10-07 Jakub Jelinek <jakub@redhat.com> * internal.h (_cpp_trigraph_map_s): New type for C++14 or later. (_cpp_trigraph_map_d): New variable for C++14 or later. (_cpp_trigraph_map): Define to _cpp_trigraph_map_d.map for C++14 or later. * init.cc (init_trigraph_map): Define to nothing for C++14 or later. (TRIGRAPH_MAP, END, s): Define differently for C++14 or later.
Diffstat (limited to 'libcpp/internal.h')
-rw-r--r--libcpp/internal.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/libcpp/internal.h b/libcpp/internal.h
index b69a037..2379fbb 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -668,6 +668,12 @@ struct cpp_embed_params
compiler that supports C99. */
#if HAVE_DESIGNATED_INITIALIZERS
extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
+#elif __cpp_constexpr >= 201304L
+extern const struct _cpp_trigraph_map_s {
+ unsigned char map[UCHAR_MAX + 1];
+ constexpr _cpp_trigraph_map_s ();
+} _cpp_trigraph_map_d;
+#define _cpp_trigraph_map _cpp_trigraph_map_d.map
#else
extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#endif