aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/utility.ixx39
-rw-r--r--libbutl/utility.mxx8
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