diff --git a/src/core/model/nstime.h b/src/core/model/nstime.h index a90ebd295..f73c47190 100644 --- a/src/core/model/nstime.h +++ b/src/core/model/nstime.h @@ -840,13 +840,6 @@ typedef void (*Time)(Time oldValue, Time newValue); } // namespace TracedValueCallback -/** - * Force static initialization order of Time in each compilation unit. - * This is internal to the Time implementation. - * \relates Time - */ -static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit(); - /** * Equality operator for Time. * \param [in] lhs The first value @@ -1490,6 +1483,27 @@ class TimeWithUnit */ TYPENAMEGET_DEFINE(Time); +/** + * \ingroup time + * + * \brief Helper class to force static initialization + * of Time in each compilation unit, ensuring it is + * initialized before usage. + * This is internal to the Time implementation. + * \relates Time + */ +class TimeInitializationHelper +{ + public: + /** Default constructor calls Time::StaticInit */ + TimeInitializationHelper() + { + Time::StaticInit(); + } +}; + +static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper + } // namespace ns3 #endif /* TIME_H */