Skip to content

Commit f6bcfaa

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 f6bcfaa

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

include/boost/optional/detail/union_optional.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,19 @@ 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+
# pragma GCC diagnostic push
80+
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
81+
#endif
82+
7783
template <class... Args>
7884
constexpr constexpr_union_storage_t( Args&&... args ) : value_(forward_<Args>(args)...) {}
7985

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

@@ -88,9 +98,19 @@ union fallback_union_storage_t
8898

8999
constexpr fallback_union_storage_t( trivial_init_t ) noexcept : dummy_() {};
90100

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

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

0 commit comments

Comments
 (0)