From c8e03f129ea52ddc8e15104d5441328f6c90647f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Jan 2022 13:15:18 +0100 Subject: [PATCH] QHashSeed: remove 'pure' attribute on globalSeed() While 'pure' in GCC is weaker than Stepanov's Regular Procedure from Elements of Programming (equal result for equal inputs), it does not allow accesses to volatile memory: > functions declared with the pure attribute can safely read any > non-volatile objects The globalSeed() function reads from an atomic variable that can be changed at any time from another thread. Atomics, while not volatile objects in the sense of the keyword, must fall under the pure attribute doc's exclusion criterion: The difference between a volatile and an atomic access, while important for the implementation of the function, is indistinguishable to the caller of the function: both volatile and atomic objects can change value without the current thread of execution changing them, with no way for the caller of the function to distinguish which one occurred. Therefore, globalSeed() should not be pure. 5.15 is not affected, as qGlobalQHashSeed() is not marked as pure. Task-number: QTBUG-62185 Pick-to: 6.3 6.2 Change-Id: I6fc52e2bd41ef4aa3f8039072b47c7a1314b98fa Reviewed-by: Fabian Kosmale Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qhashfunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index 4d0b2d95194..a3e1600600a 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -76,7 +76,7 @@ struct QHashSeed constexpr QHashSeed(size_t d = 0) : data(d) {} constexpr operator size_t() const noexcept { return data; } - static Q_CORE_EXPORT QHashSeed globalSeed() noexcept Q_DECL_PURE_FUNCTION; + static Q_CORE_EXPORT QHashSeed globalSeed() noexcept; static Q_CORE_EXPORT void setDeterministicGlobalSeed(); static Q_CORE_EXPORT void resetRandomGlobalSeed(); private: