Skip to content

Commit d154ecd

Browse files
committed
Test and fix GCC -Wpadded and MSVC 4324
1 parent 75af050 commit d154ecd

File tree

11 files changed

+96
-3
lines changed

11 files changed

+96
-3
lines changed

include/boost/decimal/cstdio.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ enum class decimal_type : unsigned
4343
decimal128_t = 1 << 2
4444
};
4545

46+
// Internal use only
47+
#ifdef __GNUC__
48+
# pragma GCC diagnostic push
49+
# pragma GCC diagnostic ignored "-Wpadded"
50+
#endif
51+
4652
struct parameters
4753
{
4854
int precision;
@@ -51,6 +57,10 @@ struct parameters
5157
bool upper_case;
5258
};
5359

60+
#ifdef __GNUC__
61+
# pragma GCC diagnostic pop
62+
#endif
63+
5464
inline auto parse_format(const char* format) -> parameters
5565
{
5666
// If the format is unspecified or incorrect, we will use this as the default values

include/boost/decimal/decimal_fast128_t.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa
8585
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
8686
#endif
8787

88-
BOOST_DECIMAL_EXPORT class decimal_fast128_t final
88+
BOOST_DECIMAL_EXPORT class alignas(16) decimal_fast128_t final
8989
{
9090
public:
9191
using significand_type = int128::uint128_t;
@@ -99,6 +99,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast128_t final
9999
significand_type significand_ {};
100100
exponent_type exponent_ {};
101101
bool sign_ {};
102+
char pad_[11] {};
102103

103104
constexpr auto isneg() const noexcept -> bool
104105
{

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa
7878

7979
} // namespace detail
8080

81-
BOOST_DECIMAL_EXPORT class decimal_fast32_t final
81+
#ifdef _MSC_VER
82+
# pragma warning(push)
83+
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
84+
#endif
85+
86+
BOOST_DECIMAL_EXPORT class alignas(4) decimal_fast32_t final
8287
{
8388
public:
8489
using significand_type = std::uint32_t;
@@ -93,6 +98,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
9398
significand_type significand_ {};
9499
exponent_type exponent_ {};
95100
bool sign_ {};
101+
char pad_[2] {};
96102

97103
constexpr auto isneg() const noexcept -> bool
98104
{
@@ -495,6 +501,10 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
495501
friend constexpr auto quantized32f(decimal_fast32_t lhs, decimal_fast32_t rhs) noexcept -> decimal_fast32_t;
496502
};
497503

504+
#ifdef _MSC_VER
505+
# pragma warning(pop)
506+
#endif
507+
498508
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool>>
499509
constexpr decimal_fast32_t::decimal_fast32_t(T1 coeff, T2 exp, const detail::construction_sign_wrapper resultant_sign) noexcept
500510
{

include/boost/decimal/decimal_fast64_t.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ constexpr auto write_payload(typename TargetDecimalType::significand_type payloa
8080

8181
} // namespace detail
8282

83-
BOOST_DECIMAL_EXPORT class decimal_fast64_t final
83+
#ifdef _MSC_VER
84+
# pragma warning(push)
85+
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
86+
#endif
87+
88+
BOOST_DECIMAL_EXPORT class alignas(8) decimal_fast64_t final
8489
{
8590
public:
8691
using significand_type = std::uint64_t;
@@ -94,6 +99,7 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
9499
significand_type significand_ {};
95100
exponent_type exponent_ {};
96101
bool sign_ {};
102+
char pad_[5] {};
97103

98104
constexpr auto isneg() const noexcept -> bool
99105
{
@@ -496,6 +502,10 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
496502
friend constexpr auto quantexpd64f(decimal_fast64_t x) noexcept -> int;
497503
};
498504

505+
#ifdef _MSC_VER
506+
# pragma warning(pop)
507+
#endif
508+
499509
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
500510
template <BOOST_DECIMAL_UNSIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
501511
#else

include/boost/decimal/detail/components.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ namespace impl {
2323
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
2424
#endif
2525

26+
27+
// Internal use only, and changes based on the types
28+
#ifdef __GNUC__
29+
# pragma GCC diagnostic push
30+
# pragma GCC diagnostic ignored "-Wpadded"
31+
#endif
32+
2633
template <typename SigType, typename BiasedExpType>
2734
struct decimal_components
2835
{
@@ -74,6 +81,10 @@ using decimal128_t_components = impl::decimal_components<boost::int128::uint128_
7481

7582
using decimal_fast128_t_components = impl::decimal_components<boost::int128::uint128_t, std::int32_t>;
7683

84+
#ifdef __GNUC__
85+
# pragma GCC diagnostic pop
86+
#endif
87+
7788
#ifdef _MSC_VER
7889
# pragma warning(pop)
7990
#endif

include/boost/decimal/detail/fenv_rounding.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ namespace detail {
1919

2020
namespace impl {
2121

22+
// These structs are for internal use only and change based on the type of T
23+
#ifdef __GNUC__
24+
# pragma GCC diagnostic push
25+
# pragma GCC diagnostic ignored "-Wpadded"
26+
#endif
27+
2228
template <typename T>
2329
struct divmod_result
2430
{
@@ -33,6 +39,10 @@ struct divmod10_result
3339
std::uint64_t remainder;
3440
};
3541

42+
#ifdef __GNUC__
43+
# pragma GCC diagnostic pop
44+
#endif
45+
3646
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
3747
constexpr auto divmod(T dividend, T divisor) noexcept -> divmod_result<T>
3848
{

include/boost/decimal/detail/from_chars_result.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ namespace decimal {
1818

1919
// 22.13.3, Primitive numerical input conversion
2020

21+
// This is how the STL says to implement
22+
#ifdef __GNUC__
23+
# pragma GCC diagnostic push
24+
# pragma GCC diagnostic ignored "-Wpadded"
25+
#endif
26+
2127
BOOST_DECIMAL_EXPORT struct from_chars_result
2228
{
2329
const char* ptr;
@@ -41,6 +47,10 @@ BOOST_DECIMAL_EXPORT struct from_chars_result
4147
constexpr explicit operator bool() const noexcept { return ec == std::errc{}; }
4248
};
4349

50+
#ifdef __GNUC__
51+
# pragma GCC diagnostic pop
52+
#endif
53+
4454
} // namespace decimal
4555
} // namespace boost
4656

include/boost/decimal/detail/remove_trailing_zeros.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ constexpr auto rotr(UInt n, unsigned int r) noexcept
2929
return (n >> r) | (n << ((bit_width - r) & (bit_width - 1)));
3030
}
3131

32+
// For internal use only and changes based on the type of T
33+
#ifdef __GNUC__
34+
# pragma GCC diagnostic push
35+
# pragma GCC diagnostic ignored "-Wpadded"
36+
#endif
37+
3238
template <typename T>
3339
struct remove_trailing_zeros_return
3440
{
3541
T trimmed_number;
3642
std::size_t number_of_removed_zeros;
3743
};
3844

45+
#ifdef __GNUC__
46+
# pragma GCC diagnostic pop
47+
#endif
48+
3949
constexpr auto remove_trailing_zeros(std::uint32_t n) noexcept -> remove_trailing_zeros_return<std::uint32_t>
4050
{
4151
std::size_t s {};

include/boost/decimal/detail/ryu/ryu_generic_128.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ BOOST_DECIMAL_INLINE_CONSTEXPR_VARIABLE unsigned_128_type one = 1;
3636
# pragma warning(disable : 4324) // Structure was padded due to alignment specifier
3737
#endif
3838

39+
// Internal use only
40+
#ifdef __GNUC__
41+
# pragma GCC diagnostic push
42+
# pragma GCC diagnostic ignored "-Wpadded"
43+
#endif
44+
3945
struct floating_decimal_128
4046
{
4147
unsigned_128_type mantissa;
4248
int32_t exponent;
4349
bool sign;
4450
};
4551

52+
#ifdef __GNUC__
53+
# pragma GCC diagnostic pop
54+
#endif
55+
4656
#ifdef _MSC_VER
4757
# pragma warning(pop)
4858
#endif

include/boost/decimal/detail/to_chars_result.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
namespace boost {
1717
namespace decimal {
1818

19+
// This is how the STL says to implement
20+
#ifdef __GNUC__
21+
# pragma GCC diagnostic push
22+
# pragma GCC diagnostic ignored "-Wpadded"
23+
#endif
24+
1925
BOOST_DECIMAL_EXPORT struct to_chars_result
2026
{
2127
char *ptr;
@@ -34,6 +40,10 @@ BOOST_DECIMAL_EXPORT struct to_chars_result
3440
constexpr explicit operator bool() const noexcept { return ec == std::errc{}; }
3541
};
3642

43+
#ifdef __GNUC__
44+
# pragma GCC diagnostic pop
45+
#endif
46+
3747
} // namespace decimal
3848
} // namespace boost
3949

0 commit comments

Comments
 (0)