Skip to content

Commit

Permalink
Merge pull request #115 from oblivioncth/bugfix/sync_error_registry
Browse files Browse the repository at this point in the history
Define AbstractError self-registration variable out-of-line to avoid multiple initializations
  • Loading branch information
oblivioncth authored Jul 23, 2023
2 parents 6812df5 + bd0d037 commit a6f65d5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/core/include/qx/core/qx-abstracterror.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ friend class Error;
static constexpr QLatin1StringView TYPE_NAME{EName.value};

private:
static inline const bool REGISTER = registerType(TYPE_CODE, TYPE_NAME);
static const bool REGISTER;

//-Constructor-------------------------------------------------------------------------------------------------------------
protected:
Expand Down Expand Up @@ -126,6 +126,15 @@ friend class Error;
// []<StringLiteral Y, quint16 Z>(AbstractError<Y, Z>&){}(type);
//};

/* Define error type registrar variable. This must be done out of line to ensure that only
* one instance of the variable exists per-error-type across an entire program. If the variable
* is defined inline, multiple versiosn of it can exist in parallel when linking via shared-libraries,
* if those libraries are used by multiple targets in the same project. This would cause an error type
* to call registerType() multiple times.
*/
template<StringLiteral EName, quint16 ECode>
const bool AbstractError<EName, ECode>::REGISTER = registerType(TYPE_CODE, TYPE_NAME);

namespace AbstractErrorPrivate
{
template<Qx::StringLiteral Y, quint16 Z>
Expand Down

0 comments on commit a6f65d5

Please sign in to comment.