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 <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-01-27 13:15:18 +01:00
parent b5c4d1f50b
commit c8e03f129e

View File

@ -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: