From fcb6beb3e86e43e03c11b3a1a4b60a77943dddfb Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 9 Oct 2022 23:15:20 +0000 Subject: [PATCH] Add check that d_array is not unsigned int or unsigned long `std::size_t` is `unsigned int` on i686-pc-linux-gnu, but is `unsigned long` on x86_64-pc-linux-gnu. This mismatch allows d_array to be well-formed on x86_64, but trigger a duplicate definition of operator[](E) on i686. Add a requires() check that forbids both types for E, so that code which would break the i686 build is also diagnosed in the x86_64 build. --- common/include/fwd-valptridx.h | 21 ++++++++++++++++----- common/main/d_array.h | 1 + common/main/fwd-d_array.h | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/include/fwd-valptridx.h b/common/include/fwd-valptridx.h index a64ad9ede..83263de1b 100644 --- a/common/include/fwd-valptridx.h +++ b/common/include/fwd-valptridx.h @@ -60,11 +60,21 @@ class valptridx : template class guarded; class array_base_count_type; - using array_base_storage_type = typename std::conditional< - std::is_enum::value, - dcx::enumerated_array, - std::array - >::type; + struct array_base_storage_integral + { + using type = std::array; + }; + /* Note: integral_type must be an `enum` type, but + * `requires(std::is_enum::value)` cannot be checked + * here, because the name `array_base_storage_enum` may be + * formed for non-enum types, but the internal type `type` will not be + * used in those cases. + */ + template + struct array_base_storage_enum + { + using type = dcx::enumerated_array; + }; protected: using const_pointer_type = const managed_type *; using const_reference_type = const managed_type &; @@ -75,6 +85,7 @@ protected: */ using typename specialized_types::integral_type; using index_type = integral_type; // deprecated; should be dedicated UDT + using array_base_storage_type = typename std::conditional::value, array_base_storage_integral, array_base_storage_enum>::type::type; public: class array_managed_type; diff --git a/common/main/d_array.h b/common/main/d_array.h index 476f300c9..1c5f4b1a5 100644 --- a/common/main/d_array.h +++ b/common/main/d_array.h @@ -24,6 +24,7 @@ namespace dcx { * Other types for E are not likely to be useful, but are not blocked. */ template +requires(!std::is_same::value && !std::is_same::value) struct enumerated_array : std::array { using base_type = std::array; diff --git a/common/main/fwd-d_array.h b/common/main/fwd-d_array.h index 9b09f485b..056d2911f 100644 --- a/common/main/fwd-d_array.h +++ b/common/main/fwd-d_array.h @@ -7,10 +7,12 @@ #pragma once #include +#include namespace dcx { template +requires(!std::is_same::value && !std::is_same::value) struct enumerated_array; }