diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-15 14:47:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-15 14:47:25 +0200 |
commit | fe7ff3cedadc33655d6a27b9410515e4e6153c0e (patch) | |
tree | 82f30d4285dd427b6045e8064a2b65d76a9e5355 | |
parent | fc5599e0a51aa42cbc3abf743790cc61f9fd94be (diff) |
Disable bogus GCC maybe used uninitialized warning with pragma
-rw-r--r-- | libbutl/utility.ixx | 39 | ||||
-rw-r--r-- | libbutl/utility.mxx | 8 |
2 files changed, 35 insertions, 12 deletions
diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index 40b7a84..55c8761 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -332,21 +332,44 @@ namespace butl return utf8_length_impl (s, nullptr, ts, wl).has_value (); } +#ifndef _WIN32 + inline const char* const* + thread_env () + { + return thread_env_; + } + + inline void + thread_env (const char* const* v) + { + // Disable bogus GCC maybe used uninitialized warning (triggered via the + // use of auto_thread_env). + // +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + + thread_env_ = v; + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + } +#endif + // auto_thread_env // inline auto_thread_env:: auto_thread_env (const char* const* new_env) { - // Note that this backwards logic (first initializing prev_env and then - // resetting it) is here to work around bogus "maybe used uninitialized" - // warning in GCC. - // - prev_env = thread_env (); + const char* const* cur_env (thread_env ()); - if (*prev_env != new_env) + if (cur_env != new_env) + { + prev_env = cur_env; thread_env (new_env); - else - prev_env = nullopt; + } } inline auto_thread_env:: diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index f329a0f..6965be4 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -291,11 +291,11 @@ LIBBUTL_MODEXPORT namespace butl LIBBUTL_SYMEXPORT void thread_env (const char* const*); #else - inline const char* const* - thread_env () {return thread_env_;} + const char* const* + thread_env (); - inline void - thread_env (const char* const* v) {thread_env_ = v;} + void + thread_env (const char* const*); #endif struct auto_thread_env |