Skip to content

Commit 88e2378

Browse files
committed
Add -Wmaybe-uninitialized pragma to union storage constructors
GCC 7+ produces false-positive -Wmaybe-uninitialized warnings at -O3 when deeply inlining through union constructors that initialize one member while another (dummy_) exists. This is the same class of false positive addressed in boostorg/variant2#55. The pragmas are placed around the forwarding constructors in both constexpr_union_storage_t and fallback_union_storage_t.
1 parent fa52755 commit 88e2378

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/boost/optional/detail/union_optional.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,20 @@ union constexpr_union_storage_t
7474

7575
constexpr constexpr_union_storage_t( trivial_init_t ) noexcept : dummy_() {};
7676

77+
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
78+
// false positive, see https://github.com/boostorg/variant2/issues/55,
79+
// https://github.com/boostorg/url/issues/979
80+
# pragma GCC diagnostic push
81+
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
82+
#endif
83+
7784
template <class... Args>
7885
constexpr constexpr_union_storage_t( Args&&... args ) : value_(forward_<Args>(args)...) {}
7986

87+
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
88+
# pragma GCC diagnostic pop
89+
#endif
90+
8091
//~constexpr_union_storage_t() = default; // No need to destroy a trivially-destructible type
8192
};
8293

@@ -88,9 +99,20 @@ union fallback_union_storage_t
8899

89100
constexpr fallback_union_storage_t( trivial_init_t ) noexcept : dummy_() {};
90101

102+
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
103+
// false positive, see https://github.com/boostorg/variant2/issues/55,
104+
// https://github.com/boostorg/url/issues/979
105+
# pragma GCC diagnostic push
106+
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
107+
#endif
108+
91109
template <class... Args>
92110
constexpr fallback_union_storage_t( Args&&... args ) : value_(forward_<Args>(args)...) {}
93111

112+
#if defined(BOOST_GCC) && (__GNUC__ >= 7)
113+
# pragma GCC diagnostic pop
114+
#endif
115+
94116
~fallback_union_storage_t(){} // My owner will destroy the `T` if needed.
95117
// Cannot default in a union with nontrivial `T`.
96118
};

0 commit comments

Comments
 (0)