aboutsummaryrefslogtreecommitdiff
path: root/libbutl/utility.ixx
diff options
context:
space:
mode:
Diffstat (limited to 'libbutl/utility.ixx')
-rw-r--r--libbutl/utility.ixx39
1 files changed, 31 insertions, 8 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::